Announcement Announcement Module
Collapse
No announcement yet.
define context listener-class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • define context listener-class

    In a web application, I define

    Code:
            <listener>
    		<listener-class>
    			org.springframework.web.context.ContextLoaderListener
    		</listener-class>
    	</listener>
    The applicationContext.xml will be in WEB-INF, but I want to put the applicationContext.xml to class path, then how should I define the listener-class

    Thanks.

  • #2
    You can create an almost-empty applicationContext.xml in WEB-INF that only has an import to the xml on the classpath, like this:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
    	<import resource="classpath*:applicationContext.xml" />
    
    </beans>

    Comment


    • #3
      Why the overhead?

      Simply define the contextConfigLocation property inside your web.xml, the ContextLoaderListener will use that to load your files.

      Code:
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
          classpath:applicationContext-file1.xml
          classpath:otherContext.xml
        </param-value>
      </context-param>

      Comment


      • #4
        From the javadocs:
        If not explicitly specified, the context implementation is supposed to use a default location (with XmlWebApplicationContext: "/WEB-INF/applicationContext.xml").
        If you have more than one xml you want to use, then Marten's example is the way to go. I still prefer to put applicationContext.xml in anyways.

        Steve O

        Comment

        Working...
        X