Eclipse configuration maven builds the spring environment

Source: Internet
Author: User

1. Environment Configuration

A) Java 1.7+

b) Eclipse Luna

c) Maven3.3.9

d) Spring 4.3.1

2. Create Maven Project

A) Open Eclipse,file->new->project->maven->maven project

b) Next

C Select the project created for WebApp, next

D fill in the project's group ID and artifact ID. Under normal circumstances, the group ID write the reverse of the domain name, artifact ID write the project name. The final point is complete.

E After the initial construction, the project directory structure is as follows

F in the general project directory, in the Java Resources directory, there are src/main/java,src/main/test/java,src/main/test/resources three source folders that need to be created manually. The following steps will cover how to make up these three directories.

3, modify the basic settings of the project

A) Right-click the project name->properties->java build path and tap the Source tab.

b) prompts Hello/src/main/java (missing) and Hello/src/test/java (missing). In the general project directory, in the Java Resources directory, there will also be src/main/test/resources this source folder. The missing is deleted first, then recreated, and the missing direct creation. Right-click the key to delete and Add. Delete the index.html in the directory, and then rebuild a index.html without an error.

c) modified complete, the effect of the following figure

D next modify the libraries configuration, the JRE uses version 1.7. Select the JRE System library->edit and replace the version.

E to modify the configuration in order and export, mainly to adjust the display sequence of these four directories, to the order you like to

f) Next modify project facets, first modify Java to 1.7.

Dynamic Web module cannot be directly modified here to 3.0, you need to open the engineering directory with a. Settings folder, open Org.eclipse.wst.common.project.facet.core.xml, and make the following modifications:

<installed facet= "Jst.web" version= "3.0"/>

Restart Eclipe to see that the change is in effect.

4, the configuration of maven in Eclipse

A) Window->properties->maven, tick download repository index updates on startup

5. Configuration of simple spring MVC

A) Open the Pom.xml file in the project and click on the Dependencies tab and click Add to add new dependencies

b If you know the dependent group ID and artifact ID, you can directly fill in, if not clear, you can enter the keyword to query, or to the http://search.maven.org site query

c The dependencies that need to be added are: SPRING-WEBMVC, version 4.1.4. Release. The complete Pom.xml file reads as follows:

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >
<modelVersion>4.0.0</modelVersion>
<groupId>zky</groupId>
<artifactId>hello</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>hello Maven webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.1.RELEASE</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.1.RELEASE</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.1.RELEASE</version>
<type>jar</type>
</dependency>


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>hello</finalName>
</build>

</project>

D Open the Src/main/webapp/web-inf/web.xml file, which is ultimately modified as follows:

<! DOCTYPE Web-app public   "-//sun Microsystems, INC.//DTD Web application 2.3//en"   "http://java.sun.com/dtd/ Web-app_2_3.dtd "> <web-app>   <display-name>archetype Created web Application</display-name  >        <!--loading Spring config file-->          <context-param>             <param-name>contextConfigLocation</param-name>       & nbsp     <!--<param-value>classpath:/configs/spring-*.xml</param-value>--><!-- -- >             <param-value>classpath*:spring-*.xml,         &NB Sp                classpath*:applicationContext.xml</param-value>   & nbsp      </context-param>          <!--Spring listening-->      
   <listener>             <listener-class> org.springframework.web.context.contextloaderlistener</listener-class>          < /listener>          <!--Spring MVC configuration-->          <servlet&
Gt               <servlet-name>Dispatcher</servlet-name>               <servlet-class>org.springframework.web.servlet.dispatcherservlet</ servlet-class>               <!--custom Spring MVC configuration file name and path-->     &N Bsp         <init-param>                   <param-na me>contextconfiglocation</param-name>                   < param-value>classpath*:spring-servlet.xml</param-value>           &nbsp   </init-param>               <load-on-startup>1</ load-on-startup>          </servlet>          <!--Spring MV C Request suffix-->          <servlet-mapping>             <serv let-name>dispatcher</servlet-name>             <url-pattern>/</ url-pattern>          </servlet-mapping>          <
welcome-file-list>             <welcome-file>index.jsp</welcome-file>
          </welcome-file-list> </web-app>

* There's a point to be noticed, Maven's new engineer has Src/main/java and src/main/resources, and it has to be spring*. XML and Applicationcontext.xml placed in these two any directory will not be an error, many other articles are written in the SRC directory, in the MAVEN environment is not good, can only be placed in Src/main/java or src/main/ Resources.

E in the Java resources/scr/main/resources directory, create the Configs folder to store the configuration path declared in Web.xml

F in the Java Resources/scr/main/resources/configs directory, create the Spring-servlet.xml, which reads as follows:

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans"   & nbsp      xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:jee= "http:// Www.springframework.org/schema/jee "         xmlns:context=" http://www.springframework.org /schema/context "xmlns:p=" http://www.springframework.org/schema/p "         xmlns:mvc=" http ://www.springframework.org/schema/mvc "xmlns:util=" Http://www.springframework.org/schema/util "         xsi:schemalocation= "Http://www.springframework.org/schema/beans                                           &NB Sp;http://www.springframework.org/schema/beans/spring-beans.xsd                                       &NBSP            http://www.springframework.org/schema/context         &NBSP ;                                   &NB Sp      http://www.springframework.org/schema/context/spring-context-4.0.xsd                                           &NB Sp        http://www.springframework.org/schema/jee               &N Bsp                                   &NB Sp     http://www.springframework.org/schema/jee/spring-jee-4.1.xsd             &N Bsp                                   &NB SP       HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC                 & nbsp                                  http  ://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd                                                   &NBSP;HTT p://www.springframework.org/schema/util                      &NBS P                             &NBSP;HTTP://WWW.SPRINGF Ramework.org/schema/util/spring-util-4.1.xsd ">                  &NBS P  <context:annotation-config/>          <context:component-scan base-package= " Com.zny.controLler "/>          <mvc:annotation-driven/>          &nbs P        <mvc:resources mapping= "/styles/**" location= "/styles/"/>          <mvc:resources mapping= "/scripts/**" location= "/scripts/"/>         &NBSP;&LT;MVC: Resources mapping= "/images/**" location= "/images/"/>            <bean   &N Bsp                class= Org.springframework.web.servlet.view.InternalResourceViewResolver ">                    <property name= "prefix" value= "/web-inf/views/"/>           & nbsp 


       <property name= "suffix" value= ". jsp"/>          </bean> </beans>
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.