保留 CGLIB 代理的注释? [英] Retain annotations on CGLIB proxies?

查看:41
本文介绍了保留 CGLIB 代理的注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 AOP 框架创建一个对象,该框架使用 CGLIB 创建代理对象.奇怪的是,增强型"代理对象没有前一个类的任何注释!

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!

谁能告诉我如何让 CGLIB 保留它创建的代理上的注释?

Can anyone tell me how can I make CGLIB retain the annotations on the proxies it creates?

干杯!尼拉夫

推荐答案

CGLIB 创建给定类的子类来生成代理.除非在注释定义中明确指定,否则子类中不会保留注释.@Inherited 注释被使用为此目的.

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

这篇关于保留 CGLIB 代理的注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆