栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring AOP CGLIB代理的字段为null

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring AOP CGLIB代理的字段为null

这是潜在的意外行为的组合。首先,Spring使用CGLIB代理AOP的bean。CGLIB代理是类的动态子类型的实例,该类将所有方法调用委派给类的真实实例。但是,即使代理是子类型的,其字段也不会初始化(即,

TargetClass
不会调用您的超级构造函数)。在这里可以找到更长的解释。

此外,您的方法

public final libvlc_media_list_t mediaListInstance() {    return mediaListInstance; // <- proxy object return null, if use aop}

要么

public final String test() {    System.out.println("TargetClass.test();");    return returnValue;}

final
。因此,CGLIB无法覆盖它们以委派给实际实例。这将在Spring日志中得到提示。例如,您会看到

22:35:31.773 [main] INFO  o.s.aop.framework.CglibAopProxy - Unable to proxy method [public final java.lang.String com.example.root.TargetClass.test()] because it is final: All calls to this method via a proxy will NOT be routed to the target instance.

将以上所有内容放在一起,您将获得一个代理实例,该实例在字段中

null
,并且该代理不能将其委托给实际实例的方法。因此您的代码实际上将调用

public final String test() {    System.out.println("TargetClass.test();");    return returnValue;}

对于

returnValue
字段为的实例
null


如果可以,请更改方法,删除

final
修饰符。如果不能,则必须重新考虑您的设计。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/495085.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号