Tôi đang gặp vấn đề với bộ điều khiển Mùa xuân của tôi - tôi nhận được không có constructor mặc định tìm thấy - nhưng họ có một constructor mà tôi đang cố gắng để tạo ra thông qua các applicationContext.xml - heres chút liên quan:Spring MVC không tìm thấy hàm tạo mặc định?
<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>
Tức là Tôi đang tạo ra một bean đầu tiên, và sau đó cố gắng để vượt qua kết quả của một cuộc gọi phương thức từ bean đó vào phương thức khởi tạo của bean thứ hai (CacheHandler).
Here'e đầu CacheHandler:
@Controller
public class CacheHandler {
private final CustomGxSessionIdCacheImpl gxSessionIdCache;
public CacheHandler(CustomGxSessionIdCacheImpl gxSessionIdCache) {
this.gxSessionIdCache = gxSessionIdCache;
}
Đây là lỗi tôi nhận được:
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>()
Bất kỳ giúp đỡ được nhiều đánh giá cao!
chúng tôi chia sẻ những ý tưởng tương tự ;-) –
Tuyệt vời, cảm ơn cho câu trả lời tất cả! – Rory
tuyệt vời để xác nhận điều này, mùa xuân cần một trong hai constructor mặc định, hoặc tự động xây dựng có dây. – lwpro2