Hemant Metalia
Hemant Metalia

Reputation: 30648

@AspectJ pointcut for execute methods of a package

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.

Upvotes: 2

Views: 10805

Answers (1)

SirVaulterScoff
SirVaulterScoff

Reputation: 704

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

Upvotes: 6

Related Questions