How to load multiple Spring application context files for a web application

Here's an example web.xml configuration file where I show how to configure the Spring Framework to properly load for a Java web application. I'm intentionally trying to keep this Spring example simple, so my web.xml file has almost the bare minimum configuration.

I show how to load the Spring ContextLoaderListener class with the listener-class tag, and also show how to load multiple Spring application context files using the context-param, param-name, and param-value XML tags.

I did leave a few extra tags in this web.xml file just to give you some context of how this configuration fits in with other tags, such as the loading of the Log4jConfigListener class, and the typical welcome-file-list tag.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     version="2.4"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      /WEB-INF/applicationContext.xml /WEB-INF/database1Context.xml /WEB-INF/database2Context.xml
    </param-value>
  </context-param>

  <listener>
    <listener-class>
      org.springframework.web.util.Log4jConfigListener
    </listener-class>
  </listener>

  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

</web-app>