第一种方式:使用默认构造函数创建
在Spring的配置文件中使用Bean标签,配以ID和Class属性之后。且没有其他属性的标签时。
采用的就是默认构造函数创建Bean对象,此时如果类中没有默认构造函数,则对象无法创建。
第二种方式:使用普通工厂创建对象
1 <bean id="instanceFactory" class="factory.InstanceFactory"></bean> 2 <bean id="accountService" factory-bean="instanceFactory" factory-method="getAccountServive"></bean>
第三种方式:使用工厂中的静态方法创建对象并存入容器
<bean id="accountService" class="actory.StaticFactory" factory-method="getAccountService"></bean>
原文:https://www.cnblogs.com/SanChauncy/p/12454835.html