spring-framework / org.springframework.beans.support / ArgumentConvertingMethodInvoker

ArgumentConvertingMethodInvoker

open class ArgumentConvertingMethodInvoker : MethodInvoker

Subclass of MethodInvoker that tries to convert the given arguments for the actual target method via a TypeConverter.

Supports flexible argument conversions, in particular for invoking a specific overloaded method.

Author
Juergen Hoeller

Since
1.1

See Also
org.springframework.beans.BeanWrapperImpl#convertIfNecessary

Constructors

<init>

ArgumentConvertingMethodInvoker()

Subclass of MethodInvoker that tries to convert the given arguments for the actual target method via a TypeConverter.

Supports flexible argument conversions, in particular for invoking a specific overloaded method.

Functions

getTypeConverter

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).

registerCustomEditor

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.

setTypeConverter

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.

Inheritors

MethodInvokingBean

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>

MethodInvokingJobDetailFactoryBean

open class MethodInvokingJobDetailFactoryBean : ArgumentConvertingMethodInvoker, FactoryBean<JobDetail>, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean

org.springframework.beans.factory.FactoryBean that exposes a org.quartz.JobDetail object which delegates job execution to a specified (static or non-static) method. Avoids the need for implementing a one-line Quartz Job that just invokes an existing service method on a Spring-managed target bean.

Inherits common configuration properties from the MethodInvoker base class, such as "targetObject" and "targetMethod", adding support for lookup of the target bean by name through the "targetBeanName" property (as alternative to specifying a "targetObject" directly, allowing for non-singleton target objects).

Supports both concurrently running jobs and non-currently running jobs through the "concurrent" property. Jobs created by this MethodInvokingJobDetailFactoryBean are by default volatile and durable (according to Quartz terminology).

NOTE: JobDetails created via this FactoryBean are not serializable and thus not suitable for persistent job stores. You need to implement your own Quartz Job as a thin wrapper for each case where you want a persistent job to delegate to a specific service method.

Compatible with Quartz 2.1.4 and higher, as of Spring 4.1.

MethodInvokingRunnable

open class MethodInvokingRunnable : ArgumentConvertingMethodInvoker, Runnable, BeanClassLoaderAware, InitializingBean

Adapter that implements the Runnable interface as a configurable method invocation based on Spring's MethodInvoker.

Inherits common configuration properties from org.springframework.util.MethodInvoker.