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>

     

       

  • 相关阅读:
    hdu4059 The Boss on Mars
    cf475D CGCDSSQ
    HDU
    cf1447D Catching Cheaters
    cf1440 Greedy Shopping
    Treats for the Cows
    dp废物学会了记录路径
    D. Jzzhu and Cities
    cf1359D Yet Another Yet Another Task
    关于sg函数打表的理解
  • 原文地址:https://www.cnblogs.com/65702708/p/2630769.html
Copyright © 2011-2022 走看看