我有我的春天控制器的问题 - 我越来越没有默认构造函数发现 - 但他们确实有这我试图通过创建applicationContext.xml的构造 - 继承人的相关位:Spring MVC没有找到默认构造函数?
<bean id="PcrfSimulator" class="com.rory.services.pcrf.simulator.PcrfSimulator" init-method="start">
</bean>
<bean id="CacheHandler" class="com.rory.services.pcrf.simulator.handlers.CacheHandler">
<constructor-arg index="0" type="com.rory.services.pcrf.simulator.CustomGxSessionIdCacheImpl">
<bean factory-bean="PcrfSimulator" factory-method="getGxSessionIdCache">
</bean>
</constructor-arg>
</bean>
即,
也就是说。我先创建一个bean,然后试图将该bean的方法调用的结果传递给第二个bean的(CacheHandler)构造函数。
Here'e CacheHandler开始:
@Controller
public class CacheHandler {
private final CustomGxSessionIdCacheImpl gxSessionIdCache;
public CacheHandler(CustomGxSessionIdCacheImpl gxSessionIdCache) {
this.gxSessionIdCache = gxSessionIdCache;
}
这里是我得到的错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheHandler' defined in URL [jar:file:/users/rtorney/Documents/apache-tomcat-7.0.25/webapps/PCRFSimulator-4.0/WEB-INF/lib/PCRFSimulator-4.0.jar!/com/rory/services/pcrf/simulator/handlers/CacheHandler.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.rory.services.pcrf.simulator.handlers.CacheHandler]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.rory.services.pcrf.simulator.handlers.CacheHandler.<init>()
任何帮助,非常感谢!
我们有着同样的想法;-) – 2012-02-15 16:25:36
大,感谢所有的答案! – Rory 2012-02-15 16:30:51
很好的证实了这一点,spring需要默认的构造函数或者自动构造函数。 – lwpro2 2013-01-04 08:54:00