Is there a shorter version of how you use MethodInvokingFactoryBean in cfg file?
Currently it is used as shown below...wondering if there is a shorter version (similar to the util namespace)
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
开发者_开发问答 <ref bean="transformation" />
</property>
<property name="targetMethod">
<value>addTransformers</value>
</property>
<property name="arguments">
<list>
<ref bean="customTransformers" />
</list>
</property>
</bean>
You can write it a bit shorter by using Spring P-Namespace
You're using very verbose syntax, you can make it shorter just by being more concise:
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="transformation"/>
<property name="targetMethod" value="addTransformers"/>
<property name="arguments">
<list>
<ref bean="customTransformers" />
</list>
</property>
</bean>
Aside from that, and maybe using the p:
syntax mentioned by @Ralph, I'm not aware of a namespace-based shortcut.
Another approach using @Configuration but for setting a System property, you can adapt though:
@Bean
public Properties retrieveSystemProperties(){
return System.getProperties();
}
private Properties systemProperties;
public Properties getSystemProperties() {
return systemProperties;
}
@Resource(name="retrieveSystemProperties")
public void setSystemProperties(Properties systemProperties) {
this.systemProperties = systemProperties;
}
@Bean
public MethodInvokingFactoryBean methodInvokingFactoryBean() {
MethodInvokingFactoryBean methodInvokingFactoryBean = new MethodInvokingFactoryBean();
methodInvokingFactoryBean.setStaticMethod("java.lang.System.setProperties");
systemProperties.setProperty("http.keepAlive", "false");
methodInvokingFactoryBean.setArguments(new Object[]{systemProperties});
return methodInvokingFactoryBean;
}
If you don't have any parameters, you can do this:
<bean id="mybean" factory-instance="otherBean" factory-method="getMyBean"/>
精彩评论