Have you considered using an anonymous bean in a MethodInvokingFactoryBean ?
<bean id="data" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetObject"><bean class="MyObject" /></property> <property name="targetMethod"><value>getData</value></property> </bean>
This is basically equivalent to what you have, except that there is no intermediate definition of a bean. I'm not sure if there will be an instance of MyObject in your ApplicationContext , however, if you need it, you can look at it.
source share