2016-04-22 67 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註釋在你的一個依賴關係中有一個類或接口的名稱,並且出於某種原因它採用了錯誤的對象。

相關問題