Announcement Announcement Module
No announcement yet.
servlets, tomcat, and app contexts Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • servlets, tomcat, and app contexts

    I have a servlet I configure via my applicationContext.xml. On web app startup, my servlet is instantiated and configured. But then, because I also have the servlet specified in the web.xml, Tomcat initializes its own without going through Spring.

    When I send a request to the servlet, the one Tomcat created is called, not the one Spring created.

    I had this issue with filters, and the DelegatingFilterProxy solved the problem. I was looking for something like that; the classes ServletForwardingController and ServletWrappingController looked promising, but I couldn't get them to work.

    I'm guessing I can't specify the servlet in the web.xml. If I do, Tomcat will try to instantiate it for me.

    My questions are:
    1. Can you have Spring configure your servlets?
    2. If so, what do you specifiy in the web.xml?
    3. Do you need to use one of ServletForwardingController or ServletWrappingController? or is there a different class?


  • #2
    You may subclass org.springframework.web.servlet.HttpServletBean. It treats config parameters as bean properties. If you need full featured resources injection, you may override initServletBean and implement dependency lookup.
    Hope this helps.