Java 如何使用aspectJ获取带注释的对象

Java 如何使用aspectJ获取带注释的对象,java,aop,aspectj,java-ee-6,pointcut,Java,Aop,Aspectj,Java Ee 6,Pointcut,我有这样一个注释: @Inherited @Documented @Target(value={ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface Restful { } @Restful public class TestAspect { public String yes; } @Pointcut("@annotation(com.rest.config.Restful)") pu

我有这样一个注释:

@Inherited
@Documented
@Target(value={ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Restful {

}
@Restful
public class TestAspect {
   public String yes;
}
@Pointcut("@annotation(com.rest.config.Restful)")
   public void pointCutMethod() {
}
我这样注释这个类:

@Inherited
@Documented
@Target(value={ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Restful {

}
@Restful
public class TestAspect {
   public String yes;
}
@Pointcut("@annotation(com.rest.config.Restful)")
   public void pointCutMethod() {
}
我有这样一个切入点:

@Inherited
@Documented
@Target(value={ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Restful {

}
@Restful
public class TestAspect {
   public String yes;
}
@Pointcut("@annotation(com.rest.config.Restful)")
   public void pointCutMethod() {
}
我试过:

@Before("pointCutMethod()")
public void beforeClass(JoinPoint joinPoint) {
    System.out.println("@Restful DONE");
    System.out.println(joinPoint.getThis());
}
但是getThis()返回null

基本上,我正在尝试获取TestSpect的对象实例。我该怎么做?有线索吗?任何帮助都将不胜感激


提前感谢

将注释仅放在类型上,切入点
@annotation(com.rest.config.Restful)
您只需要匹配类型的静态初始化连接点。正如我们可以看到的,如果您在编译时使用
-showWeaveInfo
(我将您的代码示例放入一个名为Demo.java的文件中):

如果您希望匹配该类型中的方法,它将类似于:

@Pointcut("execution(* (@Restful *).*(..))")

谢谢@Andy Clement,但正如您所看到的,我正在尝试获取一个在java ee环境中创建的实例(提示:java ee 6是标记之一),新的in-execution将无法工作。不过,它可以在se环境中工作。关于如何在EE6/7环境中实现这一点,有什么线索吗?