Spring environment: Importing jar packages, configuration file names, and placement locations

Source: Internet
Author: User

Spring environment: Importing jar packages, configuration file names, and placement locations

Now the project development in the Spring Framework application is still more, their use is not very skilled, each time with the total configuration of half a day, always some configuration is mistaken, find a time to summarize the following, convenient to build the environment when the time to use directly.

Take Spring4 as an example, here does not provide spring, the official web is easy to get down.

1. Import the relevant JAR package

After the Web project is built, import spring's own jar package Spring-beans-4.0.0.m2.jar Spring-context-4.0.0.m2.jar Spring-core-4.0.0.m2.jar Spring-expression-4.0.0.m2.jar Spring-jdbc-4.0.0.m2.jar Spring-tx-4.0.0.m2.jar Spring-web-4.0.0.M2.jar Spring-webmvc-4.0.0.m2.jar Import the jar package that spring relies on Commons-logging-1.1.1.jar import file to upload the download component Commons-fileupload-1.3.jar Commons-io-2.4.jar Import the data source jar package, here is the Apache dbcp commons-dbcp-1.4.jar Commons-pool-1.6.jar Spring The package Jstl-1.1.2.jar Standard-1.1.2.jar database driver package that needs to be added when using Jstlview in MVC, here is the MySQL Mysql-connector-java-5.1.7-bin.jar ... Other project required jar package, import jar package can first try, after the relevant configuration of the project, try to deploy the startup Web server, according to the server startup process prompts to add the missing jar package on the line until the server starts normally.

2, the name of the configuration file and placement location

2.1 default name and location the spring framework loads the applicationcontext.xml file under Classpath (classpath) By default, which is the code root of the project src/ Applicationcontext.xml, the storage directory on the server after the project is deployed is Web-inf/classes/applicationcontext.xml

2.2 Customizing the name and location Of course we can change the name of the configuration file or change the location of the file but this requires that you configure the information in the Web. xml file to tell the spring framework where to load the configuration file. Configure Contextloaderlistener or contextloaderservlet in Web. XML to specify the load path mode. These two have the same function, all implemented in the Org.springframework.web.context.ContextLoader class, all to define the contextconfiglocation parameter. The difference is that listener cannot be used in Servlet 2.2 compatible containers. Since the Servelt 2.4 specification, listener has been asked to initialize after the Web application is started. When Web. XML is initialized, Listerner checks the contextconfiglocation parameter. If it does not exist, it will use /web-inf/classes/applicationcontext.xmlby default. If it exists, it splits the string (<param-value></param-value) with a pre-defined delimiter (comma, semicolon, and space) and places the values as the application context will be searched.

1 <context-param>
2     <param-name>contextConfigLocation</param-name>
3     <param-value>/WEB-INF/conf/applicationContext.xml</param-value>
4 </context-param>
5 <listener>
6     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
7 </listener>

Spring environment: Importing jar packages, configuration file names, and placement locations

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.