Results 1 to 2 of 2

Thread: @args

  1. #1
    Join Date
    May 2011
    Posts
    10

    Default @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 at 02:29 PM.

  2. #2
    Join Date
    May 2011
    Posts
    10

    Default

    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>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •