java.lang.Objectorg.springframework.util.MethodInvoker
org.springframework.beans.support.ArgumentConvertingMethodInvoker
org.springframework.beans.factory.config.MethodInvokingFactoryBean
All Implemented Interfaces:
BeanClassLoaderAware, BeanFactoryAware, InitializingBean, FactoryBean
Note that as it is expected to be used mostly for accessing factory methods, this factory by default operates in a singleton fashion. The first request to #getObject by the owning bean factory will cause a method invocation, whose return value will be cached for subsequent requests. An internal singleton property may be set to "false", to cause this factory to invoke the target method each time it is asked for an object.
A static target method may be specified by setting the targetMethod property to a String representing the static method name, with targetClass specifying the Class that the static method is defined on. Alternatively, a target instance method may be specified, by setting the targetObject property as the target object, and the targetMethod property as the name of the method to call on that target object. Arguments for the method invocation may be specified by setting the arguments property.
This class depends on #afterPropertiesSet() being called once all properties have been set, as per the InitializingBean contract.
An example (in an XML based bean factory definition) of a bean definition which uses this class to call a static factory method:
<bean id="myObject" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="staticMethod"><value>com.whatever.MyClassFactory.getInstance</value></property> </bean>
An example of calling a static method then an instance method to get at a Java system property. Somewhat verbose, but it works.
<bean id="sysProps" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetClass"><value>java.lang.System</value></property> <property name="targetMethod"><value>getProperties</value></property> </bean> <bean id="javaVersion" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetObject"><ref local="sysProps"/></property> <property name="targetMethod"><value>getProperty</value></property> <property name="arguments"> <list> <value>java.version</value> </list> </property> </bean>
Colin - SampaleanuJuergen - Hoeller21.11.2003 - | Method from org.springframework.beans.factory.config.MethodInvokingFactoryBean Summary: |
|---|
| afterPropertiesSet, getDefaultTypeConverter, getObject, getObjectType, isSingleton, resolveClassName, setBeanClassLoader, setBeanFactory, setSingleton |
| Methods from org.springframework.beans.support.ArgumentConvertingMethodInvoker: |
|---|
| doFindMatchingMethod, findMatchingMethod, getDefaultTypeConverter, getTypeConverter, registerCustomEditor, setTypeConverter |
| Methods from org.springframework.util.MethodInvoker: |
|---|
| findMatchingMethod, getArguments, getPreparedMethod, getTargetClass, getTargetMethod, getTargetObject, getTypeDifferenceWeight, invoke, isPrepared, prepare, resolveClassName, setArguments, setStaticMethod, setTargetClass, setTargetMethod, setTargetObject |
| Methods from java.lang.Object: |
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.springframework.beans.factory.config.MethodInvokingFactoryBean Detail: |
|---|
|
|
|
null if not known in advance. |
|
|
|
|
|