2016-04-22 94 views
0

我宣布行动Spring AOP的错误:指错误类型是不是一个注释类型

@Target(ElementType.METHOD) 
@Retention(RetentionPolicy.RUNTIME) 
@Documented 
public @interface Action { 
    String name(); 
} 

的注释当我试图做一个切入点

@Aspect 
@Component 
public class LogAspect { 
    @Pointcut("@annotation(com.wisely.highlight_spinrg4.ch1.aop.Action)") //it failed here 
    public void annotationPointCut() {} 

    @After("annotationPointCut()") 
    public void after(JoinPoint joinPoint) { 
     MethodSignature signature = (MethodSignature) 
     joinPoint.getSignature(); 
     Method method = signature.getMethod(); 
     Action action = method.getAnnotation(Action.class); 
     System.out.println("Annotation Interpreter " + action.name());  
    } 

    @Before("execution(*com.wisely.highlight_spring4.ch1.aop.DemoMethodService.*(..))") 
    public void before(JoinPoint joinPoint) { 
     MethodSignature signature = (MethodSignature) 
     joinPoint.getSignature(); 
     Method method = signature.getMethod(); 
     System.out.println("Method Interpreter" + method.getName()); 
    } 
} 

它扔了一个错误: 的java .lang.IllegalArgumentException:error引用的不是注释类型:com $ wisely $ highlight_spinrg4 $ ch1 $ aop $ Action

我不知道,因为我使用了@interface来设置“Action”作为注释。任何人都可以提供帮助吗?

+0

我猜这个类型是在包名中? 'spinrg4'应该是'spring4'我猜... –

+0

这就是问题所在!非常感谢! – jiazhong

回答

0

如果您使用的是Maven,请尝试运行maven clean并安装。我怀疑Action注释在你的一个依赖关系中有一个类或接口的名称,并且出于某种原因它采用了错误的对象。

相关问题