从注释处理器应用 CGLib 代理
我有一个工作注释处理器,可以在编译时处理我的自定义注释,我想应用 CGLIB 代理来使用 MethodInterceptor
将逻辑应用到某些方法,我让这两件事独立工作。我不知道如何应用注释处理器中的 CGLIB 代码。
我想要做的是能够用我的自定义注释来注释一个类,并让它自动添加我已经应用到它的 Enhancer
代码,这样我就不必手动应用 Enhancer
我自己编码。
这似乎是编译时注释处理的完美用例。
I have a working Annotation Processor that processes my custom annotation at compile time, I want to apply a CGLIB proxy to apply logic to some of the methods using MethodInterceptor
, I have the two things working independently. I can't figure out how to apply the CGLIB code from the Annotation Processor.
What I want to do is to be able to Annotate a class with my custom annotation and have it automagically add the Enhancer
code I have working applied to it so I don't have to manually apply the Enhancer
code my self.
This seems like the perfect use case for Annotation Processing at compile time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看 http://projectlombok.org
该项目做了同样的事情。然而,不幸的是,该实现似乎依赖于编译器,因为它们依赖于 com.sun.* 类。这使得它很难在其他供应商的 JVM 实现上运行。
Have a look at http://projectlombok.org
That project does the same thing. However, unfortunately the implementation seems to be compiler dependent since they rely on com.sun.* classes. This makes it hard to run on JVM implementations of other vendors.