2016-04-22 20 views
0

ではありません私はポイントカット春AOPエラー:エラーの種類に言及注釈型

@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()); 
    } 
} 

を作るしようとするとそれがエラーを投げたアクション

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

の注釈を宣言: javaの.lang.IllegalArgumentException:参照されたエラータイプがアノテーションタイプではありません:com $ wisely $ highlight_spinrg4 $ ch1 $ aop $アクション

"アクション"を設定するために@interfaceを使用して以来、注釈として。誰も助けてくれますか?

+0

タイプがパッケージ名になっていると思いますか? 'spinrg4'は' spring4'でしょう。 –

+0

それは問題です!どうもありがとう! – jiazhong

答えて

0

Mavenを実行してみて、Mavenを使用している場合はインストールしてください。私は、アクションの注釈が、あなたの依存関係の中のクラスまたはインターフェースの名前と同じ名前で、何らかの理由で間違ったオブジェクトを取っていると思われます。