0

私は次の方法を持っています

    @AutoHandling(slot = FunctionalArea.PRE_MAIN_MENU)
    @RequestMapping(method = RequestMethod.GET)
    public String navigation(ModelMap model) {
        logger.debug("navigation");
        ...

            //First time to the Main Menu and ID-Level is ID-1 or greater
            if (!callSession.getCallFlowData().isMainMenuPlayed()
                    && callSession.getCallFlowData().getIdLevel() >= 1) {
                // Call Auto Handling                    
                logger.info("Call AutoHandling");
                autoHandlingComponent.processAutoHandling();
            }
        ...

        return forward(returnView);
    }

基本的に私がやりたいことは、processAutoHandling() にポイントカットを設定することですが、@After では @AutoHandling に slot() を使用する必要があります

これを試しましたが、呼び出されません

@Pointcut("execution(* *.processAutoHandling())")
public void processAutoHandleCall() {
    logger.debug("processAutoHandleCall");
}

@Around("processAutoHandleCall() &&" +
        "@annotation(autoHandling) &&" +
        "target(bean) "
)
public Object processAutoHandlingCall(ProceedingJoinPoint jp,
                                      AutoHandling autoHandling,
                                      Object bean)
        throws Throwable {
         ...
4

2 に答える 2

2

これにはワームホール設計パターンを使用できます。AspectJ バイトコード ベースのアプローチと構文を使用して説明していますが、Spring のプロキシ ベースの AOP を使用している場合は、明示的な ThreadLocal を使用して同じ効果を得ることができるはずです。

pointcut navigation(AutoHandling handling) : execution(* navigation(..)) 
                                             && @annotation(handling);

// Collect whatever other context you need
pointcut processAutoHandleCall() : execution(* *.processAutoHandling());

pointcut wormhole(AutoHandling handling) : processAutoHandleCall() 
                                           && cflow(navigation(handling));

after(AutoHandling handling) : wormhole(hanlding) {
   ... you advice code
   ... access the slot using handling.slot()
}
于 2011-01-21T18:56:12.407 に答える
0

a)動作しません、2つの異なるものを一致させようとしています:

@Around("processAutoHandleCall() &&" +
        "@annotation(autoHandling) &&" +
        "target(bean) "
)

processHandleCall()内部メソッドの実行autoHandlingComponent.processAutoHandling()@annotation(autoHandling)一致し、外部メソッドの実行と一致しますnavigation(ModelMap model)

b)明らかにコントローラーにアドバイスしようとしているので、いくつかの注意点があります。

  • すべてをそのまま使用する場合proxy-target-class=trueは、最終的なメソッドがないことを確認してください
  • そうでない場合は、すべてのコントローラーメソッドがインターフェイスによってサポートされ、その他のアノテーションがインターフェイス上にある必要があります。SpringMVCリファレンスドキュメントのこのセクションで@RequestMapping説明されている実装クラスではありません。
于 2011-01-21T14:29:31.047 に答える