Preparatory work:
Idea 14 editor, MAVEN project manager, Tomcat container
First, the new MAVEN project
(1) File->new->project->maven->create from archetype (maven-archetype-webapp) click "Next"
(2) Input groupid, Artifactid, Version click "Next"
(3) Select Maven version, configuration file, warehouse address click "Next"
(4) Enter project name click "Finish"
Note: The 2nd step input GroupID, Artifactid will be reflected in the Pom.xml, by GroupID and Artifactid to determine the only project. The project name entered in step 4th is reflected on the top-level folder name (the project name).
Second, configure Tomcat
(1) Run->edit configurations-> "+"->tomcat Server (local)
(2) Enter name
(3) The Server tab retains the default value
(4) Deployment tab-> "+"-> "Artifact ..."-> "Artifactid:war exploded"->ok
Note: If the 4th step does not have "artifact ..." option, then save the existing configuration directly, then right-click "Pom.xml"->maven->reimport reintroduce the next Maven file, then edit the Tomcat,deployment tab to appear "Artifact ..."
III. Structure of the project
The final folder structure is shown in the following illustration:
Where the ". Idea" folder is a folder with the idea Editor, which can be ignored.
Iv. Configuring the Spring library maven
Add in Pom.xml:
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> < Spring.version>3.1.2.release</spring.version> <mysql.verison>5.1.6</mysql.verison> < C3p0.verison>0.9.1.2</c3p0.verison> <ibatis.verison>2.3.0</ibatis.verison> < Log4j.verison>1.2.16</log4j.verison> <servlet.version>2.4</servlet.version> </properties > <dependencies> <dependency> <groupId>junit</groupId> <artifactid>junit</ar tifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <!--sp Ring start--> <dependency> <groupId>org.springframework</groupId> <artifactid>spring-c ore</artifactid> <version>${spring.version}</version> </dependency> <dependency> & Lt;groupid>org.springframework</groupid> <ARTIFACTID>SPRing-beans</artifactid> <version>${spring.version}</version> </dependency> <dependency&
Gt <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version >${spring.version}</version> </dependency> <dependency> <groupid>org.springframework& Lt;/groupid> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version > </dependency> <dependency> <groupId>org.springframework</groupId> <artifactid> ;spring-orm</artifactid> <version>${spring.version}</version> </dependency> < Dependency> <groupId>org.springframework</groupId> <artifactid>spring-jdbc</artifactid > <version>${spring.version}</version> </dependency> <dependency> <groupid>org. Springframework</groupid> <artifactid≫spring-aop</artifactid> <version>${spring.version}</version> </dependency> < Dependency> <groupId>org.springframework</groupId> <artifactid>spring-context</ Artifactid> <version>${spring.version}</version> </dependency> <!--spring End--> < /dependencies>
V. Configuration of Web.xml
Add under Webapp/web-inf/web.xml:
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>
Org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
< Param-name>contextconfiglocation</param-name>
<param-value>classpath:/spring-core.xml</ param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet >
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern >/</url-pattern>
</servlet-mapping>
Vi. Configuring Spring
Create a file named Spring-core.xml under the Resources folder, with the filename and address Web.xml <init-param><param-name> For the Contextconfiglocation <param-value> decision.
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns=
"Http://www.springframework.org/schema/beans"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema /context "
xmlns:aop=" HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP "xmlns:tx=" http://www.springframework.org/ Schema/tx "
xmlns:p=" http://www.springframework.org/schema/p "
xsi:schemalocation=" http:// Www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/ Spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-2.0.xsd
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/ Spring-aop-2.0.xsd "
default-autowire=" byname ">
</beans>