本文共 2700 字,大约阅读时间需要 9 分钟。
package com.willhonor.test.useApplicationContext3LookupOrReplaceMethods;import java.lang.reflect.Method;import java.util.UUID;import org.springframework.beans.factory.support.MethodReplacer;public class MMethodReplacer implements MethodReplacer{ public Object reimplement(Object obj, Method method, Object[] args) throws Throwable { return "String-Obj:from method-replacer-" + UUID.randomUUID(); }}
package com.willhonor.test.useApplicationContext3LookupOrReplaceMethods;import java.util.List;public class PersonA_use_lookup_method { public Object getAFFruit() { System.out.println("invoke 0"); return null; } public Object getAFFruit(String str) { System.out.println("invoke string"); return null; } public Object getAFFruit(List list) { System.out.println("invoke list"); return null; }}
package com.willhonor.test.useApplicationContext3LookupOrReplaceMethods;import java.util.List;import org.junit.Test;import org.springframework.context.support.ClassPathXmlApplicationContext;/** * bean 元素的 lookup-method/replaced-method 属性的使用 * @author jokee * */public class Test_Test_1 { @Test public void test_use_repalced_method() throws Exception { String pathA = "com/willhonor/test/configs/application.d2.xml"; String[] path = new String[] { pathA}; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(path); // PersonA_use_lookup_method persona = (PersonA_use_lookup_method) context.getBean("persona"); System.out.println("++++++++"); System.out.println(persona.getAFFruit()); System.out.println("++++++++"); System.out.println(persona.getAFFruit("")); System.out.println("++++++++"); System.out.println(persona.getAFFruit((List )null)); System.out.println("++++++++"); }}
```shell...#此处省略 spring 日志打印...++++++++invoke 0null++++++++String-Obj:from method-replacer-0fc177c9-f8d5-4e01-8fbb-a50554eff2cf++++++++String-Obj:from method-replacer-d6894628-f17d-4f8e-847a-c5c9b314d992++++++++
转载地址:http://ojlsi.baihongyu.com/