需要帮助创建使用方法注释中的值的特定切入点 [英] Need help creating a specific pointcut that utilizes a value from a method annotation

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

问题描述

我有以下方法

    @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 中,我需要将 slot() 用于 @AutoHandling

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆