答案是三种:
对于类CreateBean
public class CreateBean {
public CreateBean() {
System.out.println("create createBean");
}
public static CreateBean createInstance() {
return new CreateBean();
}
public CreateBean createBean() {
return new CreateBean();
}
}
一,<bean id="createBean" class="springdemo.CreateBean"/>
相当于:CreateBean bean = new CreateBean();
二, <bean id="createBean2" class="springdemo.CreateBean" factory-method="createInstance"/>
相当于:
CreateBean bean = new CreateBean();
CreateBean bean2 = bean.createBean();
三,<bean id="createBean3" factory-bean="createBean" factory-method="createBean" />
相当于:CreateBean.createInstance();
知道了吧?
读完这篇文章后,您心情如何?