Results 1 to 3 of 3

Thread: ContextConfigListener not working

  1. #1

    Default ContextConfigListener not working

    Hi,

    I tried to initialize contextConfigLocation with my listener class. It does not load the applicationContext xml file.

    I have set it as follows

    Code:
    <listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
    
    servlet>
    		<servlet-name>crmapp</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>	
    		<load-on-startup>1</load-on-startup>
    	</servlet>	
    
    <context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/config/spring_context/web/applicationcontext.xml</param-value>
    	</context-param>
    The code looks form crmapp-servlet.xml when I have specified that it should look for applicationcontext.xml. Please help me here.

  2. #2
    Join Date
    Jan 2007
    Location
    Kuala Lumpur, Malaysia
    Posts
    138

    Default

    if i'm not mistaken, the servlet crmapp for class org.springframework.web.servlet.DispatcherServlet causes the web application to look for crmapp-servlet.xml. this is done if you have the listener or not.
    in other words its not related to the contextConfigLocation.
    so
    basically, i think, your web application would be looking for two xml files.
    my sugestion is.
    put all the servlet related beans in crmapp-servlet.xml
    and all the non servlet related (daos, services) in your
    /WEB-INF/config/spring_context/web/applicationcontext.xml

    or if you REALLY must have all the beans in one file, just create a dummy blank
    crmapp-servlet.xml file.

    but i think putting all your beans in one file is bad (unless you have just a few beans), i try to split them up, where applicable.

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

    Default

    You have specified a ContextLoaderListener, that one will load the context files specified under the contextConfigLocation parameter.

    The DispatcherServlet will by default look at a file called [servletname]-servlet.xml.

    Normally the ContextLoaderListener (or ContextLoaderServlet) is used for loading the generic applicationContext. Normally the place where Services, DAO's etc. are located.

    The WebApplicationContext (loaded by the DispatcherServlet) normally contains only those beans which are related to the web part i.e. Controllers, ViewResolvers etc.
    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
  •