【发布时间】:2015-02-23 06:53:21
【问题描述】:
这是春豆:
@Repository
@Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class TestBean {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
这是访问 bean 的非常简单的代码:
TestBean testBean = (TestBean) SpringContext.getBean("testBean");//#1
testBean.setText("aaaaa"); //#2
System.out.println(testBean.getText()); //#3
结果是 testBean.getText() 为空。
当我尝试调试代码时,我发现 #2 中的 testBean 实例与 #3 中的实例不同。例如:
#2:TestBean@988995e #3:TestBean@69bf7e71
有什么帮助吗?谢谢!
【问题讨论】:
标签: spring proxy prototype javabeans