类 MethodInvokingBean
- java.lang.Object
- org.springframework.util.MethodInvoker
- org.springframework.beans.support.ArgumentConvertingMethodInvoker
- org.springframework.beans.factory.config.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 toMethodInvokingFactoryBean).This invoker supports any kind of target method. A static method may be specified by setting the
targetMethodproperty to a String representing the static method name, withtargetClassspecifying the Class that the static method is defined on. Alternatively, a target instance method may be specified, by setting thetargetObjectproperty as the target object, and thetargetMethodproperty as the name of the method to call on that target object. Arguments for the method invocation may be specified by setting theargumentsproperty.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
字段概要
从类继承的字段 org.springframework.util.MethodInvoker
targetClass
构造器概要
构造器 构造器 说明 MethodInvokingBean()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected TypeConvertergetDefaultTypeConverter()Obtain the TypeConverter from the BeanFactory that this bean runs in, if possible.protected ObjectinvokeWithTargetException()Perform the invocation and convert InvocationTargetException into the underlying target exception.protected Class<?>resolveClassName(String className)Resolve the given class name into a Class.voidsetBeanClassLoader(ClassLoader classLoader)Callback that supplies the beanclass loaderto a bean instance.voidsetBeanFactory(BeanFactory beanFactory)Callback that supplies the owning factory to a bean instance.从类继承的方法 org.springframework.beans.support.ArgumentConvertingMethodInvoker
doFindMatchingMethod, findMatchingMethod, getTypeConverter, registerCustomEditor, setTypeConverter
从类继承的方法 org.springframework.util.MethodInvoker
getArguments, getPreparedMethod, getTargetClass, getTargetMethod, getTargetObject, getTypeDifferenceWeight, invoke, isPrepared, prepare, setArguments, setStaticMethod, setTargetClass, setTargetMethod, setTargetObject
构造器详细资料
MethodInvokingBean
public MethodInvokingBean()
方法详细资料
setBeanClassLoader
public void setBeanClassLoader(ClassLoader classLoader)
从接口复制的说明:BeanClassLoaderAwareCallback that supplies the beanclass loaderto a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean'sInitializingBean.afterPropertiesSet()method or a custom init-method.- 指定者:
setBeanClassLoader在接口中BeanClassLoaderAware- 参数:
classLoader- the owning class loader
resolveClassName
protected Class<?> resolveClassName(String className) throws ClassNotFoundException
从类复制的说明:MethodInvokerResolve the given class name into a Class.The default implementations uses
ClassUtils.forName, using the thread context class loader.- 覆盖:
resolveClassName在类中MethodInvoker- 参数:
className- the class name to resolve- 返回:
- the resolved Class
- 抛出:
ClassNotFoundException- if the class name was invalid
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
从接口复制的说明:BeanFactoryAwareCallback 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.- 指定者:
setBeanFactory在接口中BeanFactoryAware- 参数:
beanFactory- owning BeanFactory (nevernull). The bean can immediately call methods on the factory.- 另请参阅:
BeanInitializationException
getDefaultTypeConverter
protected TypeConverter getDefaultTypeConverter()
Obtain the TypeConverter from the BeanFactory that this bean runs in, if possible.
afterPropertiesSet
public void afterPropertiesSet() throws Exception
从接口复制的说明:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- 指定者:
afterPropertiesSet在接口中InitializingBean- 抛出:
Exception- in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
invokeWithTargetException
@Nullable protected Object invokeWithTargetException() throws Exception
Perform the invocation and convert InvocationTargetException into the underlying target exception.- 抛出:
Exception