Spring中四种实例化bean的方式(2)

//测试 ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("beans.xml"); UserAction action=(UserAction)ctx.getBean("userAction_name"); action.execute();

四、实例工厂

//工厂 => public class UserDaoFactory { //这个方法不是静态的 public IUserDao createUserDaoInstance(){ return new UserDaoOracleImpl(); } }

 

 

//配置文件 <bean class="cat.action.UserAction" > <property ref="userDao_name" /> </bean> <bean class="cat.dao.UserDaoFactory" /> <bean factory-bean="userDaoFactory_name" factory-method="createUserDaoInstance" />

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/ae9c087db3a9f7b2ec9e10ae0ad98072.html