春季介绍访问原始介绍的课程 [英] Spring introduction accessing original introduced class

查看:65
本文介绍了春季介绍访问原始介绍的课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Spring框架AOP扩展一些类AImpl(实现接口A)以能够实现新的接口B.

I am trying to use Spring framework AOP to extend some class AImpl (which implements interface A) to be able to implement also new interface B.

我正在使用@DeclareParents并实现Aspect.不幸的是,我需要访问A的一些方法才能在其中实现业务逻辑.

I am using @DeclareParents and implementing Aspect. Unfortunatelly I need to access some methods of A to be able to implement business logic within it.

有没有人比将A作为参数添加到接口B方法更好的解决方案?

Does anyone knows better solution than adding A as a parameter to interface B method ?

有人成功使用Spring AOP简介来扩展类吗?我能够找到的所有示例都仅以静态方式"扩展了A类,而无需从A中调用方法.

Does anybody used successfully Spring AOP introductions to extend class in such a way I need to ? All the samples I have been able to find extends class A only in "static way" without need to call methods from A.

到目前为止,我只发现了我认为非常难看的AopContext.currentProxy()方法.

So far I have found only AopContext.currentProxy() method which I consider as very ugly hack.

推荐答案

恐怕您只有两种方法可以从B访问A

I'm afraid you have only 2 ways to get access to A from B

  • AopContext.currentProxy()-不太难看,但会强制您使用expose-proxy="true"
  • 通过Spring直接将A注入到B中-不错,因为它们都是单例的

我试图在接口B的方法上使用环绕建议,以期希望访问将实现两个接口的原始代理.但是Spring用另一个代理代替了它,该代理仅实现B来具有正确的目标.

I tried to use an around advice on a method of interface B hoping to access the original proxy that would have implemented both interfaces. But Spring replaces it by another proxy that only implements B to have a correct target.

实际上有第三种方法,但是恕我直言,这种的确很丑陋:让接口B的所有方法都显式地采用一个实现A ... bof ...:-(

There is effectively a third way but IMHO this one is really ugly : have all methods of interface B explictely take a parameter implementing A ... bof ... :-(

这篇关于春季介绍访问原始介绍的课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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