MacFlecknoe
Mar 16th, 2012, 01:58 PM
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:
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomerAnnotation {
public String name();
public String value();
}
@Aspect
public class CustomerAspect {
@Before("execution(* *(@com.example.test.annotation.CustomerAnnotation( *)))")
private void testPointCut() { // the pointcut signature
System.out.println("it works!");
}
}
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 :-/:
@Aspect
public class CustomerAspect {
@Before("@args(com.example.test.annotation.CustomerAnnotati on)")
private void testPointCut() { // the pointcut signature
System.out.println("it works!");
}
}
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomerAnnotation {
public String name();
public String value();
}
@Aspect
public class CustomerAspect {
@Before("execution(* *(@com.example.test.annotation.CustomerAnnotation( *)))")
private void testPointCut() { // the pointcut signature
System.out.println("it works!");
}
}
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 :-/:
@Aspect
public class CustomerAspect {
@Before("@args(com.example.test.annotation.CustomerAnnotati on)")
private void testPointCut() { // the pointcut signature
System.out.println("it works!");
}
}