它有两种用法:一个是调用类的静态方法,一个是调用已在IOC容器中的bean的方法。调用结果也分两种,一种是有返回,那么也会作为bean注册到IOC容器中,另一种是没有返回值,那么实际上就是为了在启动时进行方法调用而已。先看静态方法调用:

    <bean id="milletContext" class="cn.hello.millet.MilletContext" init-method="init">
<constructor-arg ref="backend" />
<property name="microServicePort" value="${microServicePort}" />
<property name="rpcServicePort" value="${rpcServicePort}" />
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="cn.hello.millet.MilletContext.setDefault" />
<property name="arguments">
<list>
<ref bean="milletContext" />
</list>
</property>
</bean>
public class ServiceDiscovery {

     public static MilletContext DEFAULT;

     public static void setDefault(MilletContext context){
   DEFAULT = context;
   MatchGroup.DEFAULT.init();
 } }

  再看实例方法调用,这里调用了jdk的System方法getProperty获取java的版本号,并注册到IOC容器已供其他bean引入。

<bean id="javaVersion" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="java.lang.System" />
<property name="targetMethod" value="getProperty"/>
<property name="arguments" value="java.version">
</bean>

  说白了MethodInvokingFactoryBean就是一个FactoryBean,看源码可知:

public class MethodInvokingFactoryBean extends MethodInvokingBean implements FactoryBean<Object>

  我们也可以自定义一个FactoryBean来生成bean,详见BeanFactory和FactoryBean

org.springframework.beans.factory.config.MethodInvokingFactoryBean的使用的更多相关文章

  1. 解决 java.lang.ClassNotFoundException: org.springframework.beans.factory.config.EmbeddedValueResolver

    1.今天用maven配置了一下dubbo的项目发现启动项目后意外报错: java.lang.ClassNotFoundException: org.springframework.beans.fact ...

  2. org.springframework.beans.factory.config.PropertyPlaceholderConfigurer类

    <bean id="investorQueryConfigurer" class="org.springframework.beans.factory.config ...

  3. java.lang.NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableBeanFactory.getSingletonMutex()Ljava/lang/Object

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述 搭建SSH框架,没有添加事务时一切正常,最后添加完事务后报错,并且怎么弄都是一样.报错信息如下: 警告: Exception encou ...

  4. org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的systemPropertiesModeName属性

    转自:https://www.cnblogs.com/huqianliang/p/5673701.html 使用PropertyPlaceholderConfigurer类载入外部配置 在Spring ...

  5. Exception in thread "main" java.lang.NoClassDefFoundError:org/springframework/beans/factory/config/EmbeddedValueResoler

    参考自:https://www.cnblogs.com/quanbin/p/11100337.html 解决方法:检查发现spring的核心包spring-bean版本和其他核心包版本不同,更改为和其 ...

  6. NoSuchMethodError: org.springframework.beans.factory.config.BeanDefinition.getResolvableType

    spring整合Mybatis报错: 解决方法: 检查maven依赖中的spring-jdbc和spring-webmvc是否版本一致 以下均为5.2.0.RELEASE版本 除此之外再检查是否有其他 ...

  7. org.springframework.beans.factory.BeanDefinitionStoreException

    org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'd ...

  8. org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSessionRepositoryFilter' is defined

    spring-session 集成redis,web.xml配置filter时候出现  No bean named 'springSessionRepositoryFilter' is defined ...

  9. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException

    1.错误描写叙述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -he ...

随机推荐

  1. Spring Cloud 之Spring-Security

    对于Spring-Security首先要明白这么几点: 1.什么是SpringSecurityurity2.SpringSecurity应用场景3.SpringBoot整合Security4.Secu ...

  2. Asp.net Core, 基于 claims 实现权限验证 - 引导篇

    什么是Claims? 这个直接阅读其他大神些的文章吧,解释得更好. 相关文章阅读: http://www.cnblogs.com/JustRun1983/p/4708176.html http://w ...

  3. python 中 正则表达式 的应用

    python 中 正则表达式 的应用 最近作业中出现了正则表达式,顺便学习了一下. python比较厉害的一点就是自带对正则表达式的支持,用起来很方便 正则表达式 首先介绍一下什么是正则表达式. 正则 ...

  4. on绑定阻止冒泡失败

    使用zepto库,有如下dom <div id="J_parent"> <a href="#"> <span>点我有惊喜&l ...

  5. 分享:JAVA各种对象

    PO:持久对象 (persistent object),po(persistent object)就是在Object/Relation Mapping框架中的Entity,po的每个属性基本上都对应数 ...

  6. 编辑器上的vim插件,常用到的快捷件

    [vim]常用到的插件命令 [Esc] 退出编辑(输入,插入)模式,回到命令模式中(常用)i, I进入插入模式(Insert mode):i 为『从目前光标所在处插入』, I 为『在目前所在行的第一个 ...

  7. 不要忘了 :focus 和 :active!

    很多人在给页面元素设计样式时忽略了它们的状态,只考虑了用户使用鼠标操作,忘记了用户也许是用键盘操作.请用 :focus 和 :active 标明它们的状态: a:hover, a:active, a: ...

  8. UVALive 4270 Discrete Square Roots

    题目描述: 在已知一个离散平方根的情况下,按照从小到大的顺序输出其他所有的离散平方根. 在模n意义下,非负整数x的离散平方根是满足0<=r<n且r2=x(mod n)的整数r. 解题思路: ...

  9. git如何回滚远程仓库

    git如何回滚远程仓库 http://www.cnblogs.com/iloveyou-sky/p/6534409.html

  10. python----模块知识拓展

    1.hashlib ------configpraser-------- xml hashlib 模块导入:import hashlib 模块说明:用于将信息加密,明文变成密文 功能说明 MD5算法 ...