它有两种用法:一个是调用类的静态方法,一个是调用已在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. mysql全库搜索指定字符串

    mysql全库搜索指定字符串 DELIMITER // DROP PROCEDURE IF EXISTS `proc_FindStrInAllDataBase`; # CALL `proc_FindS ...

  2. 分享会上演示Dubbo的路由规则,结果被小坑了下

      今天公司给大家演示基于Dubbox的服务治理平台,结果因为开了vpn导致本机IP地址比较混乱,在配置路由规则的时候我这样配置条件路由 consumer.host=*.*.*.* => pro ...

  3. 鼠标指向表格时 显示更多信息 toolTipController1

    //窗体添加 控件 ,然后将GridControl 相关属性栏对应上新加的控件 切记 本文是转帖,稍作修改 private void toolTipController1_GetActiveObjec ...

  4. C++ Primer 第二章 学习笔记

    在auto一个引用时,auto会忽略顶层const,而保存底层const decltype(sum()) x = i; // I的类型就是sum()返回值的类型

  5. SubSets,SubSets2, 求数组所有子集

    问题描述: Given a set of distinct integers, nums, return all possible subsets. Note: The solution set mu ...

  6. 一些C语言里面的编程

    C语言的知识还是不要忘的好: 1.求最大公约数的函数: #include <stdio.h> #define min(a,b) (a)>(b)?(b):(a) int gcd(int ...

  7. 10 个深恶痛绝的 Java 异常

    异常是 Java 程序中经常遇到的问题,我想每一个 Java 程序员都讨厌异常,一 个异常就是一个 BUG,就要花很多时间来定位异常问题. 今天,来列一下 Java 中经常遇到的前 10 个异常,排名 ...

  8. Android开发——View的生命周期总结

    0.前言 今天看到一个概念是View的生命周期,有点懵逼,听说过Activity的生命周期,Fragment的生命周期,对View的生命周期好像没什么概念啊.难道layout.draw这些也算是生命周 ...

  9. MapReduce程序——WordCount(Windows_Eclipse + Ubuntu14.04_Hadoop2.9.0)

    本文主要参考<Hadoop应用开发技术详解(作者:刘刚)> 一.工作环境 Windows7: Eclipse + JDK1.8.0 Ubuntu14.04:Hadoop2.9.0 二.准备 ...

  10. 在windows x64上部署使用Redis

    一.下载Redis 下载地址:https://github.com/MSOpenTech/redis/releases 二.安装Redis 将下载文件解压到D:\redis 后,可见: 三.启动Red ...