静态工厂: 用于生成实例对象 , 所有的方法必须是静态的
<bean id="" class="工厂类的全限定名" factory-method="静态方法"></bean>
工厂类
public class MyBeanFactory {
public static UserService createUserService(){
return new UserServiceImpl();
}
}
spring 配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="userService" class="com.hx.lp.staticfactory.MyBeanFactory" factory-method="createUserService"></bean>
</beans>