java @AspectJ 切入点,用于执行包的方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7802980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:29:40  来源:igfitidea点击:

@AspectJ pointcut for execute methods of a package

javaaopaspectjspring-aop

提问by Hemant Metalia

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

我想在特定的包中执行一个 execute 方法。

What could be a possible pointcut for this?

这可能是什么切入点?

Note: I am using @AspectJ style Spring AOP.

注意:我使用的是@AspectJ 风格的 Spring AOP。

回答by SirVaulterScoff

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

看看这里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).

@(org.xyz..*)匹配任何具有与类型 pattern 匹配的类型的注释的带注释的元素(org.xyz..*)。换句话说,带有在 org.xyz 包或子包中声明的注释的带注释元素。(本例中需要括号)。

So you should have the following aop config:

所以你应该有以下 aop 配置:

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

and matching bean for this advice

并为这个建议匹配 bean

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

Interceptor should implement org.aopalliance.intercept.MethodInterceptor

拦截器应该实现 org.aopalliance.intercept.MethodInterceptor