zoukankan      html  css  js  c++  java
  • Spring Bean属性绑定Bean返回值

    MethodInvokingFactoryBean 工厂bean,可以将指定方法返回值注入成为目标Bean的属性值,MethodInvokingFactoryBean用来获得指定方法的返回值,该方法可以是静态方法
    也可以是实例方法。
    获得的方法返回值既可以被注入到指定Bean实例的指定属性,也可以直接定义成Bean实例。
     

    <bean id="testfunc"  class="spring.aop.TestFunc"/>

        <!--动态方法调用-->
        <bean id="testInvok"   class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">  
           <property name="targetObject" >
           <ref local="testfunc"/>
           </property>
           <property name="targetMethod" value="test1"></property>
           <property name="arguments">
           <list>
              <value>test</value>
           </list>
           </property>
       </bean>

       <!--静态方法调用-->
        <bean id="testInvok"   class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">  
           <property name="targetClass" >//-注意这里的区别
           <ref local="testfunc"/>
           </property>
           <property name="targetMethod" value="getname"></property>
           <property name="arguments">
           <list>
              <value>test</value>
           </list>
           </property>
       </bean>
       <!--Bean属性绑定Bean返回值-->
    <bean id="testfunc"  class="spring.aop.TestFunc">
      <property name="name"
    ref="testInvok" />

    </bean>

     

       

  • 相关阅读:
    linux 定时脚本任务的创建
    win10 Edge 无法上网代理服务器错误
    CentOS 7 系统root用户忘记密码的重置方法
    通过挂载系统光盘搭建本地yum仓库的方法
    Oauth服务端协议开发
    mongodb 用户权限控制
    javascript 数组方法拼接html标签
    存储管理与linux内存寻址(1)
    原型模式
    背包,队列,栈的java实现
  • 原文地址:https://www.cnblogs.com/65702708/p/2630769.html
Copyright © 2011-2022 走看看