第一种:使用默认构造函数创建
在spring的配置文件中使用bean标签,配置id和class属性,且没有其他属性和标签时,采用的就是默认构造函数创建bean对象,如果类中没有默认构造函数,则报错
<bean id="BookImpl" class="dao.impl.BookImpl"></bean>
第二种:使用某个类中的方法创建对象并存入spring容器
<bean id="BookImpl" class="dao.impl.BookImpl"></bean> <bean id="book" factory-bean="BookImpl" factory-method="selectBooks"></bean>
第三种:使用某个类中的静态方法创建对象并存入spring容器
<bean id="bbb" class="service.impl.BookServiceImpl" factory-method="show"></bean>
原文:https://www.cnblogs.com/tongzitong/p/12531618.html