Web. XML Configuration Applicationcontext.xml

Source: Internet
Author: User

Web. XML classpath: And classpath*: What's the difference?

Classpath: Only look for files in your class path;
Classpath*: Includes not only the class path, but also the jar file (the class path) to find.


Multiple configuration files are sometimes configured in a fuzzy matching manner.

However, if the configuration file is in the jar package, the fuzzy match will not be found. Multiple configuration files can be configured in a comma-separated manner.


Such as:

<listener> <listener-class> org.springframework.web.context.contextloaderlistener</listener-class> </listener> < Context-param>      <param-name>contextconfiglocation</param-name >      <param-value>classpath*:applicationContext.xml,           classpath*:app-datasource.xml,           classpath*:app-memcached.xml,           classpath*:app-ibatis.xml,          classpath*: App-rest.xml      </param-value>  </context-param> 

Storage location:
1:SRC below
It needs to be defined in Web. Xml as follows:

<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath: Applicationcontext.xml</param-value> </context-param>

2:web-inf below
It needs to be defined in Web. Xml as follows:

<context-param> <param-name>contextConfigLocation</param-name> <param-value>web-inf/ Applicationcontext*.xml</param-value> <context-param>

Web. XML configures spring through Contextconfiglocation
SSI Framework configuration file path problem:

Struts2 1 +n paths: src+src (configurable) Name: Struts.xml + N
1 paths to spring: src Name: applicationcontext.xml
Ibatis 1 +n paths: src+src (configurable) Name: Sqlmapconfig.xml + N


After deploying to Tomcat, the configuration files in the SRC directory will be automatically copied to the application's classes directory like the class file.

When the spring configuration file is started, it loads the applicationcontext.xml in the Web-info directory,
The runtime uses applicationcontext.xml under the Web-info/classes directory.

Configure Web. XML to make these 2 paths consistent:

<context-param> <param-name>contextConfigLocation</param-name> <param-value>/web-inf/ Classes/applicationcontext.xml</param-value> <context-param>

multiple configuration file loading  

<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*: Conf/spring/applicationcontext_core*.xml, Classpath*:conf/spring/applicationcontext_dict*.xml, classpath*:conf/ Spring/applicationcontext_hibernate.xml, Classpath*:conf/spring/applicationcontext_staff*.xml, classpath*:conf/ Spring/applicationcontext_security.xml Classpath*:conf/spring/applicationcontext_modules*.xml classpath*:conf/ Spring/applicationcontext_cti*.xml Classpath*:conf/spring/applicationcontext_apm*.xml </param-value> </ Context-param>


The contextconfiglocation parameter defines the Spring configuration file to be loaded.

The first spring-related configuration file must start with "applicationcontext-", conforming to the idea that the contract is better than the configuration, which is much better in terms of efficiency and error rates.
It is also best to put all the spring configuration files in a unified directory, if the project is large, you can also sub-module to build the directory. The program does not look very messy.
The configuration in Web. XML is as follows:
XML code

<context-param> < param-name>contextconfiglocation</param-name> < param-value>classpath*:* */applicationcontext-*.xml</param-value> </context-param>

"**/" means any directory;
"**/applicationcontext-*.xml" represents an XML file that begins with "applicationcontext-" in any directory.
You can modify it yourself as needed. It is best to put all the spring configuration files in a unified directory, such as:

<!--Spring Configuration--

<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/ Spring/applicationcontext-*.xml</param-value>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.