我正在尝试使用我的servlet 3.0应用程序中的作用域请求。
我没有使用web.xml,而是使用WebApplicationInitializer的实现。 onStartup方法如下所示:
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext applicationContext =
new AnnotationConfigWebApplicationContext();
applicationContext.setServletContext(servletContext);
applicationContext.scan("package containing proxy scoped bean and other stuff");
applicationContext.refresh();
servletContext.addListener(new ContextLoaderListener(applicationContext));
servletContext.addListener(new RequestContextListener());
}
并且请求范围的bean看起来像这样:
@Component
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class CallerInformation {
private String clientIp;
public String getClientIp() {
return clientIp;
}
public void setClientIp(String clientIp) {
this.clientIp = clientIp;
}
}
现在注入"来电信息"不是CGLIB代理,但行为类似于原型范围,它是每个类中的不同实例,并且它不通过请求保存任何信息......
任何想法我做错了什么?
编辑:
我尝试过与servlet 2.5和web.xml配置相同的场景,它就像地狱一样;)