1

I'm trying to define a bean.

<bean id="prop1" class="Prop1"/>

<bean id="myBean" class="myClass">
    <property name="prop2">
        <bean class="Prop2">
    </property>
</bean>

Now I have this class

public class myClass(){
    @Autowired
    private Prop1 prop1;
    private Prop2 prop2;

    public setProp2(Prop2 prop2){
        this.prop2 = prop2;
    }
    ...
}

Im aware that I can just add property to myBean bean but I am trying to avoid that. Right now im getting null on prop1. Is it possible to initialized prop1? If not please explain or give me a link to read about this.

TIA

4

1 回答 1

1

这应该只是工作。它可能不起作用,因为您可能缺少一个AutowiredAnnotationPostProcessor,这是一个负责连接@Autowired依赖项的 bean 后处理器。您可以通过将这些添加到 xml 配置文件中来获取它:

<context:annoation-config/>

或者

<context:component-scan/>
于 2013-07-24T12:18:35.550 回答