Announcement Announcement Module
Collapse
No announcement yet.
@annotation not working in advice expression Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    Code:
    @Target({ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    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 !

    -javaagent:data/instrument/spring-instrument-3.1.0.RELEASE.jar
    -XX:-UseSplitVerifier

    This is my config:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
    	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	   xmlns:aop="http://www.springframework.org/schema/aop"
    	   xmlns:context="http://www.springframework.org/schema/context"
    	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    						   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    						   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    
    	<aop:aspectj-autoproxy/>
    	
    	<context:annotation-config/>
    	
    	<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" />
    </beans>
    And my aop.xml for extra configuration:

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

    This is the class:
    Code:
    @Aspect
    public class SecureAspect implements Serializable {
    
    	private static final long serialVersionUID = 6011153690929870440L;
    
    	private static final Logger LOGGER = LoggerFactory.getLogger(SecureAspect.class);
    	
    	/**
    	 * Constructor
    	 */
    	public SecureAspect() {
    		super();
    	}
    		
    	@Pointcut(value = "execution(public * *(..))")
    	public void anyPublicMethod() { 
    		
    	}
    
    	@Before(value = "anyPublicMethod() && @annotation(secure)")
    	public void advice(JoinPoint joinPoint, Secure secure) throws Throwable {
    		
    		LOGGER.info("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

    Code:
    @Secure
    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

    Grtz,

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

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

    Comment

    Working...
    X