//测试 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" />