Spring框架 - 如何在静态工厂方法中传递参数

时间:2015-12-30 11:47:29

标签: java spring dependency-injection

需要在静态工厂方法中传递参数,并且想要创建spring bean - 如何o,请帮助。

1 个答案:

答案 0 :(得分:1)

描述了一个工厂方法(通过XML配置)的参数here,重要的是(也参见static factory methods的文档)...

public class DaoFactoryCreator {
    public static DaoFactory createDaoFactory(List daos) {
        ... this is the factory method, do something here and return it
    }
}

<bean id="daoFactory" class="com.javalobby.tnt.spring.DaoFactoryCreator" factory-method="createDaoFactory" />
    <constructor-arg>
        <value>
            <list>
                <ref bean="dao1"/>
                <ref bean="dao2"/>
                <ref bean="dao3"/>
            </list>
        </value>
    </constructor-arg>
</bean>