它会根据默认无参构造方法来创建类对象,如果bean中没有默认无参构造函数,将会创建失败
<bean id="userDao" class="com.leon.dao.impl.UserDaoImpl"/> 工厂的静态方法返回Bean实例
public class StaticFactoryBean { public static UserDao createUserDao(){ return new UserDaoImpl(); } } <bean id="userDao" class="com.leon.factory.StaticFactoryBean" factory-method="createUserDao" /> 工厂的非静态方法返回Bean实例
public class DynamicFactoryBean { public UserDao createUserDao(){ return new UserDaoImpl(); } } <bean id="factoryBean" class="com.leon.factory.DynamicFactoryBean"/> <bean id="userDao" factory-bean="factoryBean" factory-method="createUserDao"/>