通过调用bean内的方法来调用代理AOP
可以说我有一个用两种方法“foo”和“goo”调用的bean 而'goo'则标记有AOP拦截调用。
是否可以在“foo”内编写任何代码段,以便不直接调用“goo”方法,而是通过bean的代理包装器来激活它的AOP部分?
public Class Pojo{
public void foo(){
//what should I write here in order to activate 'goo' in transactional mode??
}
@Transactional
public void goo(){
}
}
lets say the I have got a bean called with two methods 'foo' and 'goo'
and 'goo' is marked with AOP interception call.
is it possible to write any piece of code inside 'foo' in order to invoke 'goo' method not directly but through the proxy wrapper of the bean in order to activate the AOP part of it?
public Class Pojo{
public void foo(){
//what should I write here in order to activate 'goo' in transactional mode??
}
@Transactional
public void goo(){
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以,但是需要通过spring代理来访问:
Yes, but you need to access it through the spring proxy:
我无法使用自动连线选项。也许是因为我使用反射从 foo() 调用 goo() (以及任何其他方法)。
所以最终解决我的问题的是添加 foo() 代码来查找 Pojo 的代理 bean 类。并在代理 bean 上使用 Sun 调用来调用 mothd
这也调用了 AOP 调用。
找不到更好的解决方法。
I couldn't use the autowired option. Perhaps it is because I am using reflection to invoke goo() (and any other method as well) from foo().
So eventually what solves my problem was to add in foo() code that will lookup for the Pojo's proxy bean class. and invoke the mothd using Sun invokation on the proxy bean
this invoked the AOP call as well.
Couldn't find any better workaround.