这是我的弹簧配置文件:
<bean id="controller" class="com.sample.controller.Controller">
<property name="message" value="Controller1"/>
</bean>
<bean id="controller2" class="com.sample.controller.Controller2">
<property name="message" value="#{controller.message}"/>
</bean>
和代码:
ApplicationContext context =
new ClassPathXmlApplicationContext("beans.xml");
Controller obj = (Controller) context.getBean("controller");
System.out.println(obj.getMessage());
obj.message = "Controller1 changed!";
Controller2 obj2 = (Controller2) context.getBean("controller2");
System.out.println(obj2.getMessage());
我希望输出为:
Controller1
Controller1 changed!
但它是
Controller1
Controller1
除了将 Controller 注入 Controller1 之外,还有更简单的方法来获取更新的值吗?
谢谢你。