Announcement Announcement Module
Collapse
No announcement yet.
Scope("request") does not work in Servlet 3.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scope("request") does not work in Servlet 3.0

    Hello there,

    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:

    Code:
        @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 proxy scoped bean looks like this:

    Code:
    @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
    Last edited by woezelmann; Apr 25th, 2013, 04:02 AM. Reason: more information
Working...
X