Am trying to create an object using an AOP framework which uses CGLIB to create proxy objects. Strangely enough, the "enhanced" proxy object is devoid of ANY annotations the previous class had!
Can anyone tell me how can I make CGLIB retain the annotations on the proxies it creates?
Cheers! Nirav
CGLIB creates subclasses of given classes to generate proxies. Annotations are not preserved in subclasses unless explicitly specified in annotation definition. @Inherited annotation is used for this purpose.
You can use this annotation in the annotations you define, and make them reachable in subclasses, as following:
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface MyAnnotation {
}
This isn't an issue with "retaining" the annotations. CGLIB proxies are actually generated subclasses of the target object's class. These subclasses may not have annotations, but their superclass (i.e. your own class) will still have them. Any annotation-reflecting code you use needs to be able to look back up the class hierarchy to look for annotations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With