Results 1 to 4 of 4

Thread: Multiple Spring servlets?

  1. #1
    Join Date
    Sep 2006
    Location
    UK
    Posts
    39

    Question Multiple Spring servlets?

    Hi,

    Is it possible to specify multiple Spring servlets in a web.xml? If it is possible, then what values should the <context-param/> and <servlet/> elements take and how do they relate to one another?

    When I have a single Spring servlet (DispatcherServlet, acting as front controller), then I use the <context-param/> to load extra config files. So, my <context-param/> and <servlet/> elements look something like the following:
    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			classpath:dataaccessservices-config.xml
    		</param-value>
    	</context-param>
    
    	<servlet>
    		<servlet-name>frontController</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>
    				/WEB-INF/frontcontroller-servlet-config.xml
    			</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    Thanks in advance for suggestions/explanations,

    Peeper.

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

    Default

    The context-param element is only for the ContextLoaderListener NOT for you DispatcherServlet. You can have multiple DispatcherServlets. Each DispatcherServlet creates an instance of the ApplicationContext from either the [servlet-name]-servlet.xml or the value specified by the contextConfigLocation.

    Each DispatcherServlets ApplicationContext has the context loaded by the ContextLoaderListener as its root/parent applicationcontext.
    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
    Sep 2006
    Location
    UK
    Posts
    39

    Question

    Thanks for that, Marten.

    So, to clarify:

    1. ContextLoaderListener will create a root ApplicationContext - actually, a WebApplicationContext?

    2. Each Spring servlet will create its own ApplicationContext, which inherits configuration from the root ApplicationContext (which the servlet can override)?

    3. Can other types of Spring servlet (extensions of, say, FrameworkServlet) be instantiated within web.xml? - I want to manage a mail service using a vanilla servlet: http://forum.springframework.org/sho...0&postcount=25

    Thanks,

    Peeper.

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

    Default

    1. Yes
    2. Yes
    3. Sure why not...
    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
  •