spring自动调用set方法
作者:互联网
applicationContext.xml中加入了bean1和name属性
<bean name="bean1" class="bean.bean1"></bean> <bean name="bean2" class="bean.bean2"> <property name="bean1" ref="bean1"></property> <property name="name" value="test"></property> </bean>
bean2.java中的set方法加入输出语句
public void setBean1(bean1 bean1){ System.out.println("bean2注入bean1:"+bean1); this.name=bean1.getName(); } public void setName(String name) { this.name = name; System.out.println("bean2修改name:"+name); }
TempTest.java中加入
ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
运行后会先输出
bean2注入bean1:bean1 [name=123123]
bean2修改name:test
标签:set,name,spring,System,调用,bean2,bean1,out 来源: https://www.cnblogs.com/withbear/p/11839987.html