I have got a situation where I would like to create bean2 in Spring config:
beans.xml:
<bean id="bean1" class="...">
<property name="..." ref="..." />
</bean>
bean2 = bean1.foo()
Would appreciate any help,
Thanks, Behzad
I have got a situation where I would like to create bean2 in Spring config:
beans.xml:
<bean id="bean1" class="...">
<property name="..." ref="..." />
</bean>
bean2 = bean1.foo()
Would appreciate any help,
Thanks, Behzad
您可以使用实例工厂方法。请参阅Spring 文档中的相应章节。
<bean id="bean2" factory-bean="bean1" factory-method="foo"/>
如果您使用注释,您可以使用:
@Configuration
public class AppConfig {
@Bean
@Lazy
public Bean1 getBean1(){
return Bean1.getInstance();
}
@Bean
public Bean2 getBean2() {
return this.getBean1().newBean2(); //in your example is this.getBean1().foo();
}
}