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」作爲註釋。任何人都可以提供幫助嗎?
我猜這個類型是在包名中? 'spinrg4'應該是'spring4'我猜... –
這就是問題所在!非常感謝! – jiazhong