|
From: Colin S. <col...@ex...> - 2003-11-21 23:54:03
|
As per a previous message, I have added a new FactoryBean implementation
called MethodCallFactoryBean. It's a factory bean which will return the
result of a method call, either on a static class method as specified
via a fully qualified method name
package1.package2.package3.ClassName.MethodName
or alternately the result of a method call on a ref bean in the context.
The factory bean has an internal singleton property, which is true by
default. In this case, the method is only called the first time, and
subsequent invocations of getObject() on the factory will return the
exact same result. If the singleton property is set to false, then the
target method will be invoked on each call to getObject() on the bean.
The following is an example of using the new factory bean to get at a
system property:
<bean id="sysProps"
class="org.springframework.beans.factory.config.MethodCallFactoryBean">
<property
name="staticMethod"><value>java.lang.System.getProperties</value></property>
</bean>
<bean id="javaVersion"
class="org.springframework.beans.factory.config.MethodCallFactoryBean">
<property name="target"><ref local='sysProps'/></property>
<property name="targetMethod"><value>getProperty</value></property>
<property name="args">
<list>
<value>|java.version|</value>
</list>
</property>
</bean>
I just realized that most of Spring refers to method invocations, not
method calls. Would people prefer that this class be called
MethodInvocationFactoryBean instead?
Does anybody think the default value for the singleton property should
be false instead of true? My feeling is that most of the time this will
be used to call factories, so you would not want to do a method call on
each getBean() call...
Regards,
Colin
|