@AspectJ pointcut for execute methods of a package

*爱你&永不变心* 提交于 2019-12-13 16:33:10

问题


I want to execute a execute method in a specific package.

What could be a possible pointcut for this?

Note: I am using @AspectJ style Spring AOP.


回答1:


Have a look here http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations-pointcuts-and-advice.html

@(org.xyz..*) Matches any annotated element which has either an annotation of a type matching the type pattern (org.xyz..*). In other words, an annotated element with an annotation that is declared in the org.xyz package or a sub-package. (The parenthesis are required in this example).

So you should have the following aop config:

<aop:config>
 <aop:advisor advice-ref="myAdvice" pointcut="execution(* com.mycompany..*(..))" order="1"/> 
</aop:config>

and matching bean for this advice

<bean id="myadvice" class="com.mycompany.MyIntercetpor"/>

Interceptor should implement org.aopalliance.intercept.MethodInterceptor



来源:https://stackoverflow.com/questions/7802980/aspectj-pointcut-for-execute-methods-of-a-package

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