测试服务
public class DataConverterComponent { public void convert() { System.out.println("DataConverterComponent convert"); } }
cglib代理类,需要实现MethodInterceptor接口
public class DataConverterComponentInterceptor implements MethodInterceptor { @Override public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { System.out.println("DataConverterComponentInterceptor 前"); Object result = methodProxy.invokeSuper(o, args); System.out.println("DataConverterComponentInterceptor 后"); return result; } }
测试main
public class DataConverterComponentMain { public static void main(String[] args) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(DataConverterComponent.class); enhancer.setCallback(new DataConverterComponentInterceptor()); DataConverterComponent dataConverterComponent = (DataConverterComponent) enhancer.create(); dataConverterComponent.convert(); } }
标签:enhancer,class,Object,DataConverterComponentInterceptor,cglib,public,DataConvert From: https://www.cnblogs.com/use-D/p/18165377