2011-12-04 7 views
0

私はguiceを使ってメソッド傍受を実装しようとしています。 メソッドに注釈をつけてそれらを傍受でき、bindInterceptorを呼び出そうとするとエラーが発生します。Java - guiceを使ったメソッドのインターセプト?

エラーは次のとおりです。 方法bindInterceptor(マッチャー、マッチャー、MyInterceptor)はタイプMyModuleというため

未定義である私が間違って何をやっていますか?

public class MyInterceptor implements MethodInterceptor { 

    @Override 
    public Object invoke(MethodInvocation arg0) throws Throwable { 
     return arg0.proceed(); 
    } 
} 

public class MyModule extends AbstractModule { 

    @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) 
    @interface MyAnnotation {} 

    @Override 
    protected void configure() { 
      // I get an error on this line 
     bindInterceptor(Matchers.any(), Matchers.annotatedWith(MyAnnotation.class), 
       new MyInterceptor()); 
    } 
} 
+0

guice 3.0を使用しているインターセプタでコンパイルして実行することに問題はありません。あなたのインポートステートメントはどのように見えるのですか? –

答えて

3

このエラーは通常、Matchersの1、AbstractModule、またはMethodInterceptorのために間違ったimportを得ることの結果です。

これらの3つのインポート行は何ですか?

import com.google.inject.AbstractModule; 
import com.google.inject.matcher.Matchers; 
import org.aopalliance.intercept.MethodInterceptor; 
関連する問題