我有2個班彈簧構造函數依賴注入問題
public class Abcd{
private String username;
private String password;
public Abcd(@Value("${username}") String userName, @Value("${password}") String password) {
...
}
public String retrieveValues(){
......
return "someString";
}
}
public class SomeClass{
@Autowired
private Abcd obj;
public String method1(){
obj.retrieveValues();
}
我有一個xml如下。
<context:annotation-config />
<context:property-placeholder location="classpath:applNew.properties" />
<bean id="abcd" class="com.somecompany.Abcd">
<constructor-arg type="java.lang.String" value="${prop.user}" />
<constructor-arg type="java.lang.String" value="${prop.password}" />
</bean>
<bean id="someclass"
class="com.differentcompany.SomeClass">
</bean>
當我生成項目並啓動服務器,我看到下面的例外。
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'abcd' defined in URL []: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class []: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
我不明白可能是什麼問題做一個構造函數注入這種方式。有沒有解決方案?
你爲什麼在Abcd的構造函數中傳遞'@ Value'如果你傳遞了v通過春天的線索(通過'$ {prop.user}')? – sfat
@AndreiSfat:我試圖不傳遞值,然後我看到另一個異常類似的異常。 – iuser
出於某種原因,你有cglib代理的東西在那裏。你能發佈完整的spring配置嗎? – mbelow