I am working with Spring MVC controller project. Below is my Controller and I have a constructor declared which I am specifically using for testing purpose.
@Controller
public class TestController {
private static KeeperClient testClient = null;
static {
// some code here
}
/**
* Added specifically for unit testing purpose.
*
* @param testClient
*/
public TestController(KeeperClient testClient) {
TestController.testClient = testClient;
}
// some method here
}
Whenever I am starting the server, I am getting below exception -
No default constructor found; nested exception is java.lang.NoSuchMethodException:
But if I remove TestController
constructor then it works fine without any problem. What wrong I am doing here?
But if I add this default constructor then it starts working fine -
public TestController() {
}
public TestController() {}
.When you remove your custom constructor, the default constructor (no args) becomes available, but in the presence of a constructor with args, a no-args constructor is not implicitly present. - TJ-Polymorphism
. A default no-args constructor is implicit in the absence of explicitly defined constructors. - TJ-