spring-study--lookup-method--replaced-method用法

来源:互联网 发布:网络管理的功能 编辑:程序博客网 时间:2024/05/18 01:16
    <bean id="command" class="fiona.apple.AsyncCommand" scope="prototype">    </bean>    <bean id="commandManager" class="fiona.apple.CommandManagerImpl">        <lookup-method name="createCommand" bean="command" />    </bean>    <bean id="myValueCalculator" class="x.y.z.MyValueCalculator">        <replaced-method name="computeValue" replacer="replacementComputeValue">            <arg-type>String</arg-type>        </replaced-method>    </bean>    <bean id="replacementComputeValue" class="a.b.c.ReplacementComputeValue" />

说明
lookup-method:当fiona.apple.CommandManagerImpl的实例调用方法createCommand的时候,不进入createCommand方法(不实际调用该方法),直接返回command的实例
replaced-method:当x.y.z.MyValueCalculator的实例调用computeValue的方法的时候,用replacementComputeValue中的方法代替

参考文档:http://docs.spring.io/spring/docs/4.2.1.RELEASE/spring-framework-reference/htmlsingle/#beans-factory-properties-detailed