Retain annotations on CGLIB proxies?

后端 未结 4 1280
抹茶落季
抹茶落季 2020-12-06 00:44

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 t

4条回答
  •  我在风中等你
    2020-12-06 01:07

    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 {
    }
    

提交回复
热议问题