8.5. Creating beans from factory bean
You can create a bean from a factory bean as shown below:
Factory XML
<bean name="myBean" type="com.acme.MyBean"
factoryBean="com.acme.MyHelper" factoryMethod="createMyBean">
<constructors>
<constructor index="0" value="true"/>
<constructor index="1" value="Hello World"/>
</constructors>
</bean>
작은 정보
You can also use factoryBean to refer to an existing bean by bean id instead of the FQN classname.
When you use a factoryBean the, you must provide arguments as constructor tags.
For example, the class com.acme.MyHelper should be as follows:
Factory bean
public class MyHelper {
public static MyBean createMyBean(boolean important, String message) {
MyBean answer = ...
// create and configure the bean
return answer;
}
}
참고
You must make the factory method public static.