标签:bean sys 方法 return set cat struct str code
基础代码
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
People people = applicationContext.getBean("peo", People.class);
System.out.println(people);
无参构造
<bean id="peo" class="com.run.People"></bean>
有参构造
<bean id="peo" class="com.run.People">
<constructor-arg name="name" value="ych"></constructor-arg>
<constructor-arg name="age" value="30"></constructor-arg>
</bean>
public class PeopleFactory {
public People getPeople() {
return new People();
}
}
<bean id="fac1" class="com.run.PeopleFactory"></bean>
<bean id="peo" factory-bean="fac1" factory-method="getPeople"></bean>
public class PeopleFactory {
public static People getPeople1() {
People people = new People();
people.setName("ych");
return people;
}
}
<bean id="peo" class="com.run.PeopleFactory" factory-method="getPeople1"></bean>
标签:bean sys 方法 return set cat struct str code
原文地址:https://www.cnblogs.com/yinchh/p/12381097.html