Top Description Fields Constructors Methods
org.springframework.beans.factory.config

public Class MethodInvokingBean

extends ArgumentConvertingMethodInvoker
implements BeanClassLoaderAware, BeanFactoryAware, InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware
Known Direct Subclasses
org.springframework.beans.factory.config.MethodInvokingFactoryBean
Imports
java.lang.reflect.InvocationTargetException, org.springframework.beans.TypeConverter, org.springframework.beans.factory.BeanClassLoaderAware, .BeanFactory, .BeanFactoryAware, .InitializingBean, org.springframework.beans.support.ArgumentConvertingMethodInvoker, org.springframework.lang.Nullable, org.springframework.util.ClassUtils

Simple method invoker bean: just invoking a target method, not expecting a result to expose to the container (in contrast to 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>
Author
Juergen Hoeller
Since
4.0.3
See Also
MethodInvokingFactoryBean, org.springframework.util.MethodInvoker

Field Summary

Modifier and TypeField and Description
private ClassLoader
private ConfigurableBeanFactory

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

protected TypeConverter
getDefaultTypeConverter()

Overrides org.springframework.beans.support.ArgumentConvertingMethodInvoker.getDefaultTypeConverter.

Obtain the TypeConverter from the BeanFactory that this bean runs in, if possible.

protected Object
invokeWithTargetException()

Perform the invocation and convert InvocationTargetException into the underlying target exception.

protected Class<?>
resolveClassName(String
the class name to resolve
className
)

Overrides org.springframework.util.MethodInvoker.resolveClassName.

Resolve the given class name into a Class.

public void
setBeanClassLoader(ClassLoader
the owning class loader
classLoader
)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Inherited from org.springframework.beans.support.ArgumentConvertingMethodInvoker:
doFindMatchingMethodfindMatchingMethodgetTypeConverterregisterCustomEditorsetTypeConverter

Field Detail

beanClassLoaderback to summary
private ClassLoader beanClassLoader
Annotations
@Nullable
beanFactoryback to summary
private ConfigurableBeanFactory beanFactory
Annotations
@Nullable

Constructor Detail

MethodInvokingBeanback to summary
public MethodInvokingBean()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws Exception

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

Annotations
@Override
Exceptions
Exception:
in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
getDefaultTypeConverterback to summary
protected TypeConverter getDefaultTypeConverter()

Overrides org.springframework.beans.support.ArgumentConvertingMethodInvoker.getDefaultTypeConverter.

Obtain the TypeConverter from the BeanFactory that this bean runs in, if possible.

Annotations
@Override
See Also
ConfigurableBeanFactory#getTypeConverter()
invokeWithTargetExceptionback to summary
protected Object invokeWithTargetException() throws Exception

Perform the invocation and convert InvocationTargetException into the underlying target exception.

Annotations
@Nullable
resolveClassNameback to summary
protected Class<?> resolveClassName(String className) throws ClassNotFoundException

Overrides org.springframework.util.MethodInvoker.resolveClassName.

Doc from org.springframework.util.MethodInvoker.resolveClassName.

Resolve the given class name into a Class.

The default implementations uses ClassUtils.forName, using the thread context class loader.

Parameters
className:String

the class name to resolve

Returns:Class<?>

the resolved Class

Annotations
@Override
Exceptions
ClassNotFoundException:
if the class name was invalid
setBeanClassLoaderback to summary
public void setBeanClassLoader(ClassLoader classLoader)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Doc from org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class 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.

Parameters
classLoader:ClassLoader

the owning class loader

Annotations
@Override
setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean#afterPropertiesSet() or a custom init-method.

Parameters
beanFactory:BeanFactory

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override