类 MethodInvokingBean

  • 所有已实现的接口:
    Aware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean
    直接已知子类:
    MethodInvokingFactoryBean

    public class MethodInvokingBean
    extends ArgumentConvertingMethodInvoker
    implements 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>
    从以下版本开始:
    4.0.3
    作者:
    Juergen Hoeller
    另请参阅:
    MethodInvokingFactoryBean, MethodInvoker