Spring replaced-method

功能:就是替换掉 bean 中的一些方法。

public class MyValueCalculator {
 
    public String computeValue(String input) {
        // some real code...
    }
}

方法覆写,注意要实现 MethodReplacer 接口:

public class ReplacementComputeValue implements 
    org.springframework.beans.factory.support.MethodReplacer {
 
    public Object reimplement(Object o, Method m, Object[] args) throws Throwable {
        // get the input value, work with it, and return a computed result
        String input = (String) args[0];
        ...
        return ...;
    }
}

配置也很简单:


    
    
        String
    

 

arg-type 明显不是必须的,除非存在方法重载,这样必须通过参数类型列表来判断这里要覆盖哪个方法。

转自:https://javadoop.com/post/spring-ioc

你可能感兴趣的:(Spring replaced-method)