【发布时间】:2013-06-08 23:38:51
【问题描述】:
我正在使用 Spring 3 AOP,并且我有一个方面需要访问 HttpServletRequest。它看起来像这样:
@Aspect
public class MyAspect {
@Autowired
private HttpServletRequest httpServletRequest;
public void init() {
// Do something once...
}
@Before("my pointcut here...")
private void myMethod() {
// I need the httpServletRequest...
}
@After("my pointcut here...")
private void myOtherMethod() {
// I need the httpServletRequest...
}
}
并且是这样配置的:
<bean id="myAspect" class="com.some.package.MyAspect" init-method="init" />
每个 IoC 容器是否只调用一次 init 方法,即使这是一个方面,并且 httpServletRequest 线程是否安全?如果不是,那么在执行建议期间获取它并使其成为线程安全的最佳方法是什么?如果可能的话,我宁愿不使用本地线程。
【问题讨论】:
标签: spring servlets thread-safety aop spring-aop