open class MethodInvokingBean : ArgumentConvertingMethodInvoker, BeanClassLoaderAware, BeanFactoryAware, InitializingBean
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
MethodInvokingFactoryBeanorg.springframework.util.MethodInvoker
MethodInvokingBean()
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 This class depends on An example (in an XML based bean factory definition) of a bean definition which uses this class to call a static initialization method:
An example of calling an instance method to start some server bean:
|
open fun afterPropertiesSet(): Unit |
|
open fun setBeanClassLoader(classLoader: ClassLoader): Unit |
|
open fun setBeanFactory(beanFactory: BeanFactory): Unit |
open fun getTypeConverter(): TypeConverter
Return the TypeConverter used for argument type conversion. Can be cast to org.springframework.beans.PropertyEditorRegistry if direct access to the underlying PropertyEditors is desired (provided that the present TypeConverter actually implements the PropertyEditorRegistry interface). |
|
open fun registerCustomEditor(requiredType: Class<*>, propertyEditor: PropertyEditor): Unit
Register the given custom property editor for all properties of the given type. Typically used in conjunction with the default org.springframework.beans.SimpleTypeConverter; will work with any TypeConverter that implements the PropertyEditorRegistry interface as well. |
|
open fun setTypeConverter(typeConverter: TypeConverter): Unit
Set a TypeConverter to use for argument type conversion. Default is a org.springframework.beans.SimpleTypeConverter. Can be overridden with any TypeConverter implementation, typically a pre-configured SimpleTypeConverter or a BeanWrapperImpl instance. |
open class MethodInvokingFactoryBean : MethodInvokingBean, FactoryBean<Any>
FactoryBean which returns a value which is the result of a static or instance method invocation. For most use cases it is better to just use the container's built-in factory method support for the same purpose, since that is smarter at converting arguments. This factory bean is still useful though when you need to call a method which doesn't return any value (for example, a static class method to force some sort of initialization to happen). This use case is not supported by factory methods, since a return value is needed to obtain the bean instance. 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 NOTE: If your target method does not produce a result to expose, consider MethodInvokingBean instead, which avoids the type determination and lifecycle limitations that this MethodInvokingFactoryBean comes with. This invoker supports any kind of target method. A static method may be specified by setting the This class depends on An example (in an XML based bean factory definition) of a bean definition which uses this class to call a static factory method:
An example of calling a static method then an instance method to get at a Java system property. Somewhat verbose, but it works.
|