用cglib两层代理后会报错
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(Hello.class);
enhancer.setCallback(new TestAop());
Hello hello = (Hello)enhancer.create();
Enhancer enhancer1 = new Enhancer();
enhancer1.setSuperclass(hello.getClass());
enhancer1.setCallback(new TestAop());
Hello hello2 = (Hello)enhancer1.create();
System.out.println(hello2.getClass());
hello2.dd();
报错
at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:413)
at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336)
... 12 more
Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file tk/tankpao/blast/util/Hello$$EnhancerByCGLIB$$59850fd3$$EnhancerByCGLIB$$2199b39
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
... 18 more
有没类似的方式实现多层代理(优雅,cglib类似的工具库已经提供了多层代理的功能)。
通过往一个切面里织入多次代码,也能实现多次代理,但是本人觉得不够优雅。