[英]Is it possible to inject a property through autowired when that bean already has another property set through xml
我正在尝试定义一个bean。
<bean id="prop1" class="Prop1"/>
<bean id="myBean" class="myClass">
<property name="prop2">
<bean class="Prop2">
</property>
</bean>
现在我上这堂课
public class myClass(){
@Autowired
private Prop1 prop1;
private Prop2 prop2;
public setProp2(Prop2 prop2){
this.prop2 = prop2;
}
...
}
我知道我可以将属性添加到myBean bean中,但是我试图避免这种情况。 现在,我在prop1上获得了空值。 可以初始化prop1
吗? 如果没有,请解释或给我链接以阅读有关此内容。
TIA
这应该工作。 它可能不起作用,因为您可能缺少AutowiredAnnotationPostProcessor
,它是负责在@Autowired
依赖项中进行接线的bean后处理器。 您可以通过将它们添加到xml配置文件中来获得它:
<context:annoation-config/>
要么
<context:component-scan/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.