这是潜在的意外行为的组合。首先,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修饰符。如果不能,则必须重新考虑您的设计。



