When Using Dynamic Proxies, how do I access the underlying object's Annotations?
使用动态代理时,如何访问基础对象的注释?
Specifically I'm annotating settings of a ORM object with @Column("client_id") and then making a Dynamic Proxy keep track of when the annotated setters are called, but...
具体来说,我用@Column(“client_id”)注释ORM对象的设置,然后使动态代理跟踪调用带注释的setter的时间,但是......
It doesn't seem that the annotated proxy keeps any of the underlying annotations so short of performing reflection on every invocation, how do I make the proxy have the annotations of the class it's Proxying?
似乎注释代理不会使任何底层注释在每次调用时都没有执行反射,我如何使代理具有它所代表的类的注释?
Thank you, Allain
谢谢Allain
1 个解决方案
#1
4
AFAIK, it depends on your bytecode injection lib. Also, remember that typically annotations are not inherited (imposed by the Java spec). If you want to access the original class, and are using CGLIB, you can use this snippet:
AFAIK,它取决于你的字节码注入lib。另外,请记住,通常不会继承注释(由Java规范强加)。如果要访问原始类,并且正在使用CGLIB,则可以使用以下代码段:
if (Enhancer.isEnhanced(getClass())) {
currClass = UnEnhancer.unenhance(getClass());
} else {
// else, let's get the original class directly
currClass = getClass();
}
#1
4
AFAIK, it depends on your bytecode injection lib. Also, remember that typically annotations are not inherited (imposed by the Java spec). If you want to access the original class, and are using CGLIB, you can use this snippet:
AFAIK,它取决于你的字节码注入lib。另外,请记住,通常不会继承注释(由Java规范强加)。如果要访问原始类,并且正在使用CGLIB,则可以使用以下代码段:
if (Enhancer.isEnhanced(getClass())) {
currClass = UnEnhancer.unenhance(getClass());
} else {
// else, let's get the original class directly
currClass = getClass();
}