问题
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