本文介绍了需要帮助来创建利用方法注释中的值的特定切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下方法

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

Basically what I want to do, is have a pointcut on processAutoHandling()But in the @After, I need to use the slot() for @AutoHandling

我尝试了这个,但是没有被调用

I tried this, but it does not get called

@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 {
         ...

推荐答案

您可以为此使用虫孔设计模式.我正在说明使用基于AspectJ字节码的方法和语法,但是如果您使用的是基于Spring的基于代理的AOP,则应该可以使用显式的ThreadLocal达到相同的效果.

You can use the wormhole design pattern for this. I am illustrating using AspectJ byte-code based approach and syntax, but you should be able to get the same effect using an explicit ThreadLocal if you are using Spring's proxy-based AOP.

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

这篇关于需要帮助来创建利用方法注释中的值的特定切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:22