public class MethodInvokingBean extends ArgumentConvertingMethodInvoker implements BeanClassLoaderAware, BeanFactoryAware, InitializingBean
MethodInvokingFactoryBean).
This invoker supports any kind of target method. A static 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 initialization method:
<bean id="myObject" class="org.springframework.beans.factory.config.MethodInvokingBean"> <property name="staticMethod" value="com.whatever.MyClass.init"/> </bean>
An example of calling an instance method to start some server bean:
<bean id="myStarter" class="org.springframework.beans.factory.config.MethodInvokingBean"> <property name="targetObject" ref="myServer"/> <property name="targetMethod" value="start"/> </bean>
MethodInvokingFactoryBean,
MethodInvoker| Constructor and Description |
|---|
MethodInvokingBean() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
protected TypeConverter |
getDefaultTypeConverter()
Obtain the TypeConverter from the BeanFactory that this bean runs in,
if possible.
|
protected java.lang.Object |
invokeWithTargetException()
Perform the invocation and convert InvocationTargetException
into the underlying target exception.
|
protected java.lang.Class<?> |
resolveClassName(java.lang.String className) |
void |
setBeanClassLoader(java.lang.ClassLoader classLoader)
Callback that supplies the bean
class loader to
a bean instance. |
void |
setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance.
|
doFindMatchingMethod, findMatchingMethod, getTypeConverter, registerCustomEditor, setTypeConverterpublic void setBeanClassLoader(java.lang.ClassLoader classLoader)
BeanClassLoaderAwareclass loader to
a bean instance.
Invoked after the population of normal bean properties but
before an initialization callback such as
InitializingBean's
InitializingBean.afterPropertiesSet()
method or a custom init-method.
setBeanClassLoader in interface BeanClassLoaderAwareclassLoader - the owning class loader; may be null in
which case a default ClassLoader must be used, for example
the ClassLoader obtained via
ClassUtils.getDefaultClassLoader()protected java.lang.Class<?> resolveClassName(java.lang.String className)
throws java.lang.ClassNotFoundException
resolveClassName in class org.springframework.util.MethodInvokerjava.lang.ClassNotFoundExceptionpublic void setBeanFactory(BeanFactory beanFactory)
BeanFactoryAwareInvoked after the population of normal bean properties
but before an initialization callback such as
InitializingBean.afterPropertiesSet() or a custom init-method.
setBeanFactory in interface BeanFactoryAwarebeanFactory - owning BeanFactory (never null).
The bean can immediately call methods on the factory.BeanInitializationExceptionprotected TypeConverter getDefaultTypeConverter()
getDefaultTypeConverter in class ArgumentConvertingMethodInvokerConfigurableBeanFactory.getTypeConverter()public void afterPropertiesSet()
throws java.lang.Exception
InitializingBeanThis method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet in interface InitializingBeanjava.lang.Exception - in the event of misconfiguration (such
as failure to set an essential property) or if initialization fails.protected java.lang.Object invokeWithTargetException()
throws java.lang.Exception
java.lang.Exception