Results 1 to 4 of 4

Thread: My HttpRequestHandler is not ServletConfigAware (why?)

Hybrid View

  1. #1
    Join Date
    Jul 2011
    Posts
    8

    Default My HttpRequestHandler is not ServletConfigAware (why?)

    Hello,

    I need a ServletConfigAware servlet that I have already configured as a HttpRequestHandler @Controller invoked by HttpRequestHandlerServlet.

    Unfortunately, my ServletConfigAware.setServletConfig() method is never called.

    I have modified the HttpRequestHandlerServlet to call ServletConfigAware.setServletConfig() if the target servlet is a ServletConfigAware, but there must be a cleaner way to do it.

    Do you know what I should do?

    If it helps, I added the ContextLoaderListener and RequestContextListener listeners to my web.xml, and also the contextConfigLocation pointing to classpath:applicationContext.xml where I use the <context:component-scan> tag to make Spring look for my annotated beans (this works, the only problem is the ServletConfigAware interface; Spring is not "aware" of it!). I don't use Spring MVC (just servlets and also Jersey integrated with Spring).

    Thanks in advance!

    Ferran

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    And why should it? There is no servletconfig in the ContextLoaderListener... The thing is called ServletConfig for a reason it belongs to a servlet and hence is only available for the DispatcherServlet. The ContextLoaderListener doesn't know anything about a ServletConfig...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jul 2011
    Posts
    8

    Default

    But the HttpRequestHandlerServlet knows about the ServletConfig, although it never passes it to the HttpRequestHandler target it manages. I supposed there would be a way to do it.

    Do you think I need the DispatcherServlet? I saw that class is from the Spring MVC and I don't use Spring MVC. Is it OK to use it anyway? In that case, how should I configure my beans (my servlets and other non-servlet beans)? Now I just have an applicationContext.xml. Should I move all my beans to a servletContext.xml or only the servlet beans? In case I separate the contexts, how would my servlet beans see my non-servlet beans?

    I know I should ask some of those questions in other threads, but I already tried to find the answers with no luck.

    Thank you very much!
    Ferran
    Last edited by ferranmc; Nov 24th, 2011 at 03:39 AM.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default


    But the HttpRequestHandlerServlet knows about the ServletConfig, although it never passes it to the HttpRequestHandler target it manages. I supposed there would be a way to do it.
    That doesn't matter... The problem is you are loading the config with the ContextLoaderlIstener if doesn't matter how many servlets you have. The fact remains the ContextLoaderListener is loading the configuration and that knows nothing about a ServletConfig.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •