is it possible to make a @Aspect request scope in spring

不想你离开。 提交于 2020-02-03 16:17:46

问题


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

Example:

@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
    }
}

And in XML:

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

回答1:


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.



来源:https://stackoverflow.com/questions/7194331/is-it-possible-to-make-a-aspect-request-scope-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!