Announcement Announcement Module
Collapse
No announcement yet.
@args Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @args

    Can someone post a working example of how to use @args in an aspect? I have an annotation that I am trying to use to "mark" certain string arguments as a "customer_id" so that I can perform a security check on them:

    Code:
    @Retention(RetentionPolicy.RUNTIME)
    public @interface CustomerAnnotation {
    
    	public String name();
    	public String value();
    }
    Code:
    @Aspect
    public class CustomerAspect {
    
    	@Before("execution(* *(@com.example.test.annotation.CustomerAnnotation(*)))")
    	private void testPointCut() { // the pointcut signature
    		System.out.println("it works!");
    	}
    }
    Code:
    public class TestCommand {
    
    	public void execute(@CustomerAnnotation(name = "foo", value = "foo") String customer_id) {
    		System.out.println("executed");
    	}
    }
    I have tried what seems like a trillion ways to get "it works!" to print out but nothing works :-(

    I have also tried this approach to no avail :-/:

    Code:
    @Aspect
    public class CustomerAspect {
    
    	@Before("@args(com.example.test.annotation.CustomerAnnotation)")
    	private void testPointCut() { // the pointcut signature
    		System.out.println("it works!");
    	}
    }
    Last edited by MacFlecknoe; Mar 16th, 2012, 02:29 PM.

  • #2
    For completenss here is the bean file:

    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"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
    	
    	<aop:aspectj-autoproxy/>
    	<bean 
    		id="aspect" 
    		class="com.example.test.aspect.CustomerAspect" />
    	<bean 
    		name="command" 
    		class="com.example.test.TestCommand"/>
    </beans>

    Comment

    Working...
    X