Announcement Announcement Module
Collapse
No announcement yet.
WebApplicationContext is loaded twice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • WebApplicationContext is loaded twice

    I have a servlet-based application running in Tomcat 5 that uses a single applicationContext.xml file. When the app starts, WebApplicationContext is loaded and all declared beans are created and initialized. Next thing a second thread pops-up and immediately starts loading WebApplicationContext again.
    Like so:

    - Using context class [org.springframework.web.context.support.XmlWebAppl icationContext] for root WebApplicationContext
    - Root WebApplicationContext: initialization completed in 4166 ms
    - Root WebApplicationContext: initialization started
    - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]



    Then I have two sets of singletons all over the place. Here are links to log output, applicationContext.xml and web.xml.
    If someone can help I really appreciate it

    Clickable links:
    log.txt
    applicationContext.xml
    web.xml

  • #2
    Post your applicationContext.xml.

    Comment


    • #3
      Did you notice three links at the bottom? One of these is applicationContext.xml

      Comment


      • #4
        Do any of your servlets extend ContextLoaderServlet, or otherwise invoke ContextLoader.initWebApplicationContext ?

        If not, I'd recommend logging a bit more information (ie the class and maybe line number where the log statement emanates), or use a debugger to find out where and why ContextLoader.initWebApplicationContext is getting called from.

        Comment


        • #5
          No it's a single plain vanilla Servlet. Here's the code:

          Code:
          public class NewsServlet extends HttpServlet {
          	private Logger logger = Logger.getLogger(NewsServlet.class);
          
          	private Dispatcher dispatcher;
          
          	/**
          	 * Returns information about the servlet, such as author, version, and
          	 * copyright.
          	 * 
          	 * @return String information about this servlet
          	 */
          	public String getServletInfo() {
          		return "News Servlet";
          	}
          
          	/**
          	 * Initialization of the servlet. <br>
          	 * 
          	 * @throws ServletException
          	 *             if an error occure
          	 */
          	public void init&#40;&#41; throws ServletException &#123;
          		ServletContext servletContext = getServletConfig&#40;&#41;.getServletContext&#40;&#41;;
          		WebApplicationContext springContext = WebApplicationContextUtils
          				.getRequiredWebApplicationContext&#40;servletContext&#41;;
          		dispatcher = &#40;Dispatcher&#41; springContext.getBean&#40;"dispatcher"&#41;;
          	&#125;
          
          	protected void service&#40;HttpServletRequest request,
          			HttpServletResponse response&#41; throws ServletException, IOException &#123;
          
          		RequestDispatcher requestDispatcher = request
          				.getRequestDispatcher&#40;dispatcher.dispatch&#40;request, response&#41;&#41;;
          		requestDispatcher.forward&#40;request, response&#41;;
          	&#125;
          
          &#125;

          Comment


          • #6
            And if you look at web.xml (see link above) I'm not even pre-loading it

            Comment


            • #7
              bostone I didn't see the links. You applicationContext looks okay and also the web.xml. If you don't load your code somewhere else in your code I think you have defined your web application twice inside Tomcat (usually this happens if you are using an IDE).

              Comment


              • #8
                Thanks for suggestion; I think I'm onto something.
                No, I have a single webapp and behavior is same ether from IDE or as standalone. However, here's the catch: my app is trying to be a webservice and webapp simultaneously. Webservice is run by Axis servlet and I also added new custom servlet to the Axis webapp to have a regular HTML interface. Webservice (run by Axis servlet) and my servlet (each running in its own thread) are sharing same codebase, they both will ask Spring context for the manager bean which does all the work. For some reason the web context is loaded for both servlets - Axis and mine. If I disable Axis servlet, then context is loaded only once.
                So here's my question: why? I only define a single listener in the web.xml and both servlets are defined in same web.xml, so why web context is loaded twice then by each servlet?

                Comment

                Working...
                X