首页 > 代码库 > spring静态工厂方法得到单例bean

spring静态工厂方法得到单例bean

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Repository;


public final class TaskFactory {

    private static TaskFactory instance;

    private TaskFactory() {

    }

    public static TaskFactory getInstance() {
        if (instance == null) {
            instance = new TaskFactory();
        }
        return instance;
    }

    
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <description></description>
    
    
    <bean id="taskFactory" class="com.yundaex.common.parent.threadpool.TaskFactory"
        factory-method="getInstance">
    </bean>
</beans>

 

spring静态工厂方法得到单例bean