I have Java classes like this:
public class Config {
public Config1 getConfigOpt1();
public Config2 getConfigOpt2();
}
public class SomeBean {
public Config getEntireConfig();
}
public class BeanToConstruct {
public static BeanToConstruct createAndStart( Config1 config1, Config2 config2 )
}
Given SomeBean
, I would construct BeanToConstruct like this:
SomeBean someBean = ....
BeanToConstruct bean = BeanToConstruct.createAndStart(
someBean.getEntireConfig().getConfigOpt1(),
someBean.getEntireConfig().getConfigOpt2() )
How can I do this inside my applicationContext.xml? This is basically what I want to do, but it obviously doesn't work. I could pull the entire Config object out into its own bean, but I don't want to have this extra bean around that is really only needed to make constructing BeanToConstruct possible.
<bean class="com.example.SomeBean" id="someBean"/>
<bean class="com.example.BeanToConstruct" factory-method="createAndStart" id="myBean">
<constructor-arg>
<bean factory-bean="someBean" factory-method="getEntireConfig().getConfigOpt1()"/>
</constructor-arg>
<constructor-arg>
<bean factory-bean="someBean" factory-method="getEntireConfig().getConfigOpt2()"/>
</constructor-arg>
</bean>