I am trying to insert a constructor that takes some arguments. After compiling, Spring complains that it could not find the default constructor (I did not define it) and throws a BeanInstatiationException and a NoSuchMethodException.
After defining the default constructor, exceptions are no longer displayed, however, my object is never initialized by the argument constructor, only by default are called. In this case, is Spring the default constructor required? And if so, how can I get it to use the argument constructor instead of the standard?
Here's how I spend it all:
public class Servlet { @Autowired private Module module; (code that uses module...) } @Component public class Module { public Module(String arg) {} ... }
Bean Configuration:
<beans> <bean id="module" class="com.client.Module"> <constructor-arg type="java.lang.String" index="0"> <value>Text</value> </constructor-arg> </bean> ... </beans>
Stack trace:
WARNING: Could not get url for /javax/servlet/resources/j2ee_web_services_1_1.xsd ERROR initWebApplicationContext, Context initialization failed [tomcat:launch] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'module' defined in URL [...]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.client.Module]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.client.Module.<init>()
source share