First look at the Web. XML configuration
1 <!--load Spring Container configuration -2 <Listener>3 <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class>4 </Listener>5 6 <!--set the path for the spring container to load all the configuration files -7 <Context-param>8 <Param-name>Contextconfiglocation</Param-name>9 <Param-value>Classpath*:config/applicationcontext.xml</Param-value>Ten </Context-param>
Directory structure
When I configure this, no matter how to modify the path settings in Web. XML, start Tomcat and always fail to load applicationcontext.xml. After a painful ordeal, I found only files in the Webroot directory deployed to Tomcat. The Config folder is not deployed to Tomcat at all.
When I moved the config folder below the Webroot, I found it was still wrong and still couldn't load the Applicationcontext.xml file. It turns out that the "classpath*:config/applicationcontext.xml" file path was incorrectly written. After the "classpath*:" is removed, it can be loaded correctly.
Classpath: The resource file under the Classpath is loaded. All of the applicationcontext.xml are placed under SRC so that the configuration system can be loaded correctly. (Deployed to Tomcat after the Web-inf/classes folder)
Classpath*: The resource under the SRC file will be loaded, and all resources including the jar file will be loaded.
Path settings for spring configuration file Applicationcontext.xml