我有我的春天控制器的問題 - 我越來越沒有默認構造函數發現 - 但他們確實有這我試圖通過創建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