Announcement Announcement Module
No announcement yet.
@annotation not working in advice expression Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @annotation not working in advice expression

    Hi all,

    I am currently playing around with AOP etc.. I am introducing it into my application. I created a @Secure annotation. The thing I want to do is, when a method has this annotation, it should be intercepted because some security things need to be done at first.

    Secure annotation:
    public @interface Secure {
    Be aware, I don't use Spring's application context. So I use load time weaving to make my beans aspect aware through Spring. I also have to pass the following VM arguments in order to let it all work !


    This is my config:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
    	<context:load-time-weaver aspectj-weaving="on" weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
    	<bean id="coreLogAspect" class="be.elitetagger.core.aspect.CoreLogAspect"/>
    	<bean id="eventDispatchThreadAspect" class="be.elitetagger.core.aspect.EventDispatchThreadAspect" />
    	<bean id="secureAspect" class="be.elitetagger.core.aspect.SecureAspect" />
    And my aop.xml for extra configuration:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "">
    	<weaver options="-noverify -showWeaveInfo -Xlint:ignore">
    		<exclude within="be.elitetagger.*"/>
    		<aspect name="be.elitetagger.core.aspect.CoreLogAspect"/>
    		<aspect name="be.elitetagger.core.aspect.EventDispatchThreadAspect"/>
    		<aspect name="be.elitetagger.core.aspect.SecureAspect"/>
    When I boot application all aspects work except the SecureAspect one..

    This is the class:
    public class SecureAspect implements Serializable {
    	private static final long serialVersionUID = 6011153690929870440L;
    	private static final Logger LOGGER = LoggerFactory.getLogger(SecureAspect.class);
    	 * Constructor
    	public SecureAspect() {
    	@Pointcut(value = "execution(public * *(..))")
    	public void anyPublicMethod() { 
    	@Before(value = "anyPublicMethod() && @annotation(secure)")
    	public void advice(JoinPoint joinPoint, Secure secure) throws Throwable {
   "Secure method intercepted !");
    When I remove the && @annotation(secure), the aspect seems to work. Any ideas on how to solve this so that any public method that has the @Secure annotation will be intercepted ?

    I start application and i have a button that triggers this method

    public void test() {
    that is located in a class in be.elitetagger.view package so it should be eligible for weaving !
    I have no errors during start up of application and all aspects are registered successfully. The CoreLogAspect and EventDispatchThreadAspect seems to work because i see weave info and logging of the aspects ...

    I use Spring v3.1.0 core, aspects and instrumentation, ApectJ (rt, tools and weaver) v1.7.2 dependencies.

    In my opinion it has something to do with bad Pointcut expression orso ... I tried like 100 different combinations and perhaps it looks the @annotation is ignored somehow ...

    Thanks in advance


    Last edited by Kristof303; Jun 11th, 2013, 04:01 PM.

  • #2
    No Aspects/Weaver (lol) experts here ??? hehe ...