1

アーキテクチャなどをチェックするいくつかの側面を備えた単純なspringbootアプリケーションを構築しました。

System.out.println() へのすべての呼び出しをキャッチして、使用法に関する警告を表示しようとしているので、これまでに見つけたものです:

System.out.println() は PrintStream を使用するため、これを試しました:

@Aspect
@Component
public class CleanCodeAspect {

    @Before("call(void java.io.PrintStream.println(String))")
    public void beforePrintlnCall() {
        System.out.println("About to make call to print Hello World");
   }

}

しかし、成功しませんでした。ログは言う

The pointcutexpression call(void java.io.PrintStream.println(String)) contains unsupported pointcut primitive 'call'

同様のアスペクトが機能していますが、呼び出しの代わりに実行しています:

@Aspect
@Component
public class BooleanServiceMonitor {

    @Before("execution(* de.fhb..*Service.*(java.lang.Boolean))")
        public void logServiceAccess() {
            System.out.println("You used a method with only one boolean parameter. "
                    + "Refactor it into 2 methods with True, False at the end.");
        }

    }
4

1 に答える 1

1

Spring はプロキシを使用して AOP を適用し、Spring は Spring ベースの Bean のみをプロキシできます。クラスの実装PrintStreamは、通常、Spring 構成の Bean ではありません。次に、Spring AOP は(メッセージが示すように) AspectJ構文のサブセットのみをサポートし、(特に) サポートするものと特別なポイントカットをサポートします。executionbean

より多くの機能 (callポイント カットなど) を使用したい場合は、本格的な AspectJをロード時またはコンパイル時の織り込みで使用する必要があります。

于 2014-11-20T13:59:20.250 に答える