本文介绍了在春天可以做一个@Aspect请求范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在春季提出@Aspect请求范围?因为它似乎不起作用,而且很有道理;代理对象实际上并没有注入到任何地方,建议仅由运行时应用.只是想知道...

is it possible to make a @Aspect request scope in spring? Because it seems that it doesn't work, and it kind of makes sense; the proxy object isn't actually injected anywhere, the advice is just applied by the runtime. Just wondering...

示例:

@Aspect
public class MyAspect {
    // expecting this to get autowired per request
    @Autowired private HttpServletRequest request;

    @Around(...)
    public void doSomething(ProceedingJoinPoint pjp) {
        // something here
        pjp.proceed();
        // something there
    }
}

在XML中:

<bean class="MyAspect" scope="request" />

推荐答案

而不是使用方面,而是实现 HandlerInterceptor .然后,您可以轻松访问所有常见对象(包括Request),并具有pre和post处理方法.

Rather than using an aspect, implement HandlerInterceptor. Then you have simple access to all of the usual objects, including the Request, and have pre and post handle methods.

这篇关于在春天可以做一个@Aspect请求范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:04