我有两个抽象类
class abstract A {
//some methods .
}
class abstract B extends A {
private C c ;
//other methods
}
Spring 配置文件:
<bean id="b" class="B" abstract="true">
<property name="c" ref="C" /> //I have reference for C else where
</bean>
当我运行程序时,类 c 没有被注入(inject)。它将以 null 形式出现。我错过了什么吗?
最佳答案
abstract=true
表示该 bean 规范是其他 bean 声明扩展的"template",并不意味着该类是抽象的。我怀疑 id b
的 bean 没有被创建,因为它是一个模板/抽象定义。删除 abstract=true
并使 B
成为具体类型,它应该可以工作。
此处的文档:http://static.springsource.org/spring/docs/3.0.x/reference/beans.html#beans-child-bean-definitions
关于java - spring中注入(inject)抽象类的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5220178/