No default constructor found; nested exception is java.lang.NoSuchMethodException with Spring MVC?

john :

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() {

    }
prashant thakre :

You must have to define no-args or default constructor if you are creating your own constructor.

You can read why default or no argument constructor is required.

why-default-or-no-argument-constructor-java-class.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error creating bean with name 'application', No default constructor found; nested exception is java.lang.NoSuchMethodException

Spring Request processing failed; nested exception is java.lang.NoSuchMethodException:

Spring MVC no default constructor found?

Spring MVC - nested exception is java.lang.NullPointerException

Custom Spring Condition causes java.lang.NoSuchMethodException: <init>() exception

Error creating bean in spring , Constructor threw exception; nested exception is java.lang.NullPointerException

Error: java.lang.NoSuchMethodException: java.lang.Long.<init>() in spring MVC

NoSuchMethodException when parameter of java.lang.Integer is passed in constructor (Reflection)

Why Scala needs duplicate constructor? (java.lang.NoSuchMethodException)

Spring @Autowired constructor gives No default constructor found

Failed to instantiate class HeroController; constructor threw exception; nested exception is java.lang.NullPointerException

Spring framework MVC - Hibernate exception is java.lang.NoSuchMethodError

Spring-boot, unable to autowire a class.No default constructor found Exception is raised

Caused by: java.lang.NoSuchMethodException Spring Batch xml configuration

Spring boot No default constructor found on @SpringBootApplication class

ElasticSearch SpringBoot+Spring Data: java.lang.IllegalStateException: No suitable constructor found on interface

Java reflection: constructor for primitive int causes: java.lang.NoSuchMethodException: int.<init>(int)

No default constructor found with Java record and BeanPropertyRowMapper

spring security oauth2 java config - Handler dispatch failed; nested exception is java.lang.StackOverflowError

No primary or default constructor found for interface java.util.List Rest API Spring boot

java.lang.NoSuchMethodException for onCreate

java.lang.NoSuchMethodException: <init> []

No exception found but mail not send in Spring MVC

Cannot construct Spring webClient due to java.lang.IllegalStateException: No suitable default ClientHttpConnector found

Spring Boot : Handler dispatch failed; nested exception is java.lang.NoSuchMethodError

Spring: nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

Handler dispatch failed; nested exception is java.lang.AbstractMethodError: error only in WAS but not in spring embedded tomcat

ConfigServletWebServerApplicationContext: nested exception is java.lang.NoClassDefFoundError: jakarta/servlet/jsp/JspFactory using Tomcat 10 - Spring

Exception while starting up the server : java.lang.NoSuchMethodException: org.springframework.security.authentication.ProviderManager.<init>()