I am trying to use a request scoped been inside my servlet 3.0 application.
I am not using the web.xml but an implementation of WebApplicationInitializer. The onStartup method looks like this:
@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());
}
and the request scoped bean looks like this:
@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;
}
}
Now the injected "CallerInformation" is not a CGLIB-proxy but behaves like prototype scoped, it is a different instance in every class and it does not hold any information through the request...
Any ideas what I am doing wrong?
EDIT:
I have tried the same scenario with servlet 2.5 and web.xml config and it worked like hell ;)