Spring aop intercepting calls from within the same service class

帅比萌擦擦* 提交于 2019-12-04 10:04:04
pap

For this to work, you have to use load-time weaving instead of proxying. The reason is because spring uses proxying to achieve AOP functionality (such as transaction support). Once inside a class instance, any method-calls to methods in the same instance will be directly against the actual instance object, not the wrapping proxy so AOP advices will not be considered. Load-time weaving works differently. There, you have an outside java agent that manipulates the classes on a byte-code level to inject the AOP support.

You will need to

1: Modify your java command-line used to include the spring aspectj agent

2: add

<context:load-time-weaver aspectj-weaving="on" />
<tx:annotation-driven mode="aspectj" />

to your spring cofig.

Read more:

AspectJ Load Time Weaving with Spring Transaction Manager and Maven

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-aj-ltw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!