Eclipse uses Maven to build spring MVC graphic tutorial

This article introduces the detailed steps of using Maven to build spring MVC in eclipse for your reference. The specific contents are as follows

1. Environment configuration

a). Java 1.7

b). Eclipse luna

c). Maven3. two point five

d). Spring 4.1. four

2. Create Maven project

a). Open eclipse, file - > New - > Project - > Maven - > Maven project

b). next step

c). Select webapp as the created project. Next

d). Fill in the group ID and artifact ID of the item. Generally, group ID is written in the reverse order of domain names, and artifact ID is written in the item name. Finish at the last point.

e). After initial construction, the project directory structure is as follows

f). In the general project directory, under the Java resources directory, there are three source folders: Src / main / Java, Src / main / test / Java, and Src / main / test / resources, which need to be created manually. In the following steps, we will talk about how to supplement these three directories.

3. Modify project basic settings

a). Right click the project name - > properties - > java build path, and click the source tab.

b). Prompt hello / SRC / main / Java (missing) and hello / SRC / test / Java (missing). In the general project directory, the source folder Src / main / test / resources also exists in the Java resources directory. Delete missing first and then create again. Create missing ones directly. Right click the operation key to delete and add.

c). The modification is complete, and the effect is shown in the figure below

d). Next, modify the configuration of libraries and JRE use version 1.7. Select JRE system library - > Edit to change the version.

e). Modify the configuration in order and export, mainly to adjust the display order of these four directories to the order you like

f). Next, modify the project facets. First, modify java to 1.7.

The dynamic web module cannot be directly modified to 3.0 here. You need to open one under the project directory Settings folder, open org eclipse. wst. common. project. facet. core. XML, modify as follows:

Restart eclipse to see the changes take effect.

4. Configuration of Maven in eclipse

a). Window - > properties - > maven, check download repository index updates on startup

5. Simple spring MVC configuration

a). Open POM. In the project XML file, click the dependencies tab, and click Add to add a new dependency

b). If you know the dependent group ID and artifact ID, you can fill them in directly. If you are not clear, you can enter keywords for query or go to http://search.maven.org Website query

c). The dependencies to be added are: spring webmvc, version 4.1 4. RELEASE。 Complete POM The contents of the XML file are as follows:

d). Open Src / main / webapp / WEB-INF / Web XML file. The final modification is as follows:

e). In the Java resources / SCR / main / resources directory, create the configs folder for storage on the web Configuration path declared in XML

f). In the Java resources / SCR / main / resources / configurations directory, create a spring servlet XML, as follows:

g). Create the controller package in spring servlet In the XML file, < context: component scan base package = "com. Springstudy. Controller" / > the path has been specified

h). In Src / main / webapp / WEB-INF directory, create the views file in spring servlet In the XML file, < property name = "prefix" value = "/ Web inf / views / / > the view file path has been specified

i). Create the first controller file hellocontroller Java, the complete file contents are as follows:

j). Add Src / main / webapp / WEB-INF / views / Hello JSP file, as follows:

6. Publish project to Tomcat

a). Add Tomcat 7 in eclipse;

b). After adding tomcat, double-click to set the server locations in the overview tab;

i. Select use Tomcat installation (takes control of Tomcat installation)

ii. Change the content of the deploy path to: webapps

III. preservation

c). Right click tomcat, add and remove... To add study

d). Start Tomcat;

e). Browser open @ h_ 301_ 229@http : / / localhost: 8080 / study / Hello, access succeeded! As shown below:

End of operation!

The above is all about how eclipse uses Maven to build spring MVC. I hope it can give you a reference and support more programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>