Spring configuration file –applicationcontext.xml file path

Source: Internet
Author: User

Spring configuration file –applicationcontext.xml file pathJava Programming

The default address for spring configuration file Applicationcontext.xml is Web-inf, as long as the code is added to Web. xml

1 2 3 5 < Span style= "FONT-SIZE:16PX;" >< listener > < > org.springframework.web.context.contextloaderlistener </ listener-class > </ listener >

Spring will be loaded automatically

But in the actual development process, we may need to adjust the position of the Applicationcontext.xml to make the program structure more clear. In Web. XML, the code for configuring the spring configuration file is as follows:

1 2 3 4 <context-param><param-name>contextConfigLocation</param-name><param-value>这里写路劲</param-value></context-param>

According to the API description of the spring framework, there are four ways to configure the Applicationcontext.xml file path

1./web-inf/applicationcontext.xml

2. Com/config/applicationcontext.xml

3. File:c:/javacode/springdemo/com/config/applicationcontext.xml

4. Classpath:com/config/applicationcontext.xml

Note: The above path is just an example, specific use or to the real project, do the programming of this point extrapolate ability or some of it

In the development process, if spring's configuration file applicationcontext.xml is not loaded, the general return of such errors

Could not open ServletContext resource [/web-inf/applicationcontext.xml]

Here's a common way for you to customize Applicationcontext.xml paths for example.

1. Spring configuration file under Web-inf

In this case you can not take care of him, do not configure, because spring will default to load, if it must be configured, you can

1 2 3 4 <context-param><param-name>contextConfigLocation</param-name><param-value>WEB-INF/applicationContext.xml</param-value></context-param>

2, spring configuration file under Web-inf under a folder, such as config, you can configure this

1 2 3 <context-param><param-name>contextConfigLocation</param-name><param-value>WEB-INF/config/applicationContext.xml</param-value></context-param>

3, spring configuration file under SRC, this can be configured

1 2 3 <init-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></init-param>

Or

1 2 3 <context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param>

4, spring configuration file in a package under SRC, such as Com.config, can be configured like this

1 2 3 <context-param><param-name>contextConfigLocation</param-name><param-value>WEB-INF/classes/com/config/applicationContext.xml</param-value></context-param>

Or

1 2 3 <context-param><param-name>contextConfigLocation</param-name><param-value>classpath:com/config/applicationContext.xml</param-value></context-param>
Article source http://www.codingwhy.com/81.html

Detailed –applicationcontext.xml file path for spring configuration file

Related Article

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.