One, I use the tool is IntelliJ idea +tomcat8+jdk8
Two
1. First create a MAVEN Web project
Next
Next
Click "Finish"
Add the packages that depend on the pom.xml.
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Projectxmlns= "http://maven.apache.org/POM/4.0.0"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">5 <modelversion>4.0.0</modelversion>6 7 <groupId>GroupId</groupId>8 <Artifactid>Learnspringmvc</Artifactid>9 <version>1.0-snapshot</version>Ten One <!--Packaging Methods - A <Packaging>War</Packaging> - - <Dependencies> the <Dependency> - <groupId>Org.springframework</groupId> - <Artifactid>Spring-core</Artifactid> - <version>4.2.6.RELEASE</version> + </Dependency> - <Dependency> + <groupId>Org.springframework</groupId> A <Artifactid>Spring-beans</Artifactid> at <version>4.2.6.RELEASE</version> - </Dependency> - <Dependency> - <groupId>Org.springframework</groupId> - <Artifactid>Spring-aspects</Artifactid> - <version>4.2.6.RELEASE</version> in </Dependency> - <Dependency> to <groupId>Org.springframework</groupId> + <Artifactid>Spring-webmvc</Artifactid> - <version>4.2.6.RELEASE</version> the </Dependency> * <Dependency> $ <groupId>Org.springframework</groupId>Panax Notoginseng <Artifactid>Spring-context</Artifactid> - <version>4.2.6.RELEASE</version> the </Dependency> + </Dependencies> A </Project>
If you need to add the packages needed for your project later, add them in this format:
<dependency>36 <groupid>org.springframework</groupid>37 <artifactId> spring-context</artifactid>38 <version>4.2.6.release</version>39 </dependency >
Once added, right-click the import jar package in the project's Pom.xml file, such as:
2. If your idea tool is configured with local tomcat
If there is no red box in the Web and spring, click on the "+" above to add it up.
When you are done adding,
Add dispatcher Front controller to Web. xml
1 <!DOCTYPE Web-app Public2 "-//sun Microsystems, INC.//DTD Web application 2.3//en"3 "Http://java.sun.com/dtd/web-app_2_3.dtd">4 5 <Web-app>6 <servlet>7 <Servlet-name>Myspringmvc</Servlet-name>8 <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>9 <Init-param>Ten <Param-name>Contextconfiglocation</Param-name> One <Param-value>Classpath:mvc-dispatcher-servlet.xml</Param-value> A </Init-param> - <Load-on-startup>1</Load-on-startup> - </servlet> the <servlet-mapping> - <Servlet-name>Myspringmvc</Servlet-name> - <Url-pattern>/</Url-pattern> - </servlet-mapping> + </Web-app>
Note that the:<url-pattern>/</url-pattern> here don't write <url-pattern>/*</url-pattern>
The Mvc-dispatcher-servlet.xml code is as follows:
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 Xmlns:context= "Http://www.springframework.org/schema/context"5 xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd " >6 7 <Context:component-scanBase-package= "Com.controller"/>8 </Beans>
Create a Java folder, and create a Com.controller package under the Java folder clip.
1 PackageCom.controller;2 ImportOrg.springframework.stereotype.Controller;3 Importorg.springframework.web.bind.annotation.RequestMapping;4 ImportOrg.springframework.web.bind.annotation.ResponseBody;5 ImportOrg.springframework.web.bind.annotation.RequestMethod;6 7 @Controller8@RequestMapping (value = "/main")9 Public classMaincontroller {Ten@RequestMapping (method =requestmethod.get) One @ResponseBody A PublicString Welcome () { - return"Test Web"; - } the}
Last added. You can access it after you launch Tomcat successfully.
My first summary, if in doubt please leave a message below, for reference only.
IntelliJ idea 2017-Beginner's SPRINGMVC project to build a simple maven