Spring Series 1--idea Spring MVC maven Project

Source: Internet
Author: User
Tags aop tomcat server log4j
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> &LT;ARTIFACTID&GT;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&gt ;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&Gt;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>  




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.