1. Environmental information
MyEclipse2015,jdk1.8,tomcat8
2. Create a new MAVEN project
2.1 新建一个web项目
2.2 生成的项目结构如下
3. Configuring the Pom.xml File
3.1 pom.xml完整信息
<?xml version= "1.0" encoding= "UTF-8"? ><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/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <groupid>com.qfx </groupId> <artifactId>springbootDemo01</artifactId> <version>0.0.1-snapshot</version > <packaging>war</packaging> <name>springbootDemo01</name> <description> Fill in descriptive information here </description> <!--set up the parent class, consolidating third-party common framework Dependency information (various dependency information)--<parent> <groupid>org.springframew Ork.boot</groupid> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0. 4.release</version> <relativePath/> <!--lookup parent from repository to </parent> <!--set public parameters--<properties> <projecT.build.sourceencoding>utf-8</project.build.sourceencoding> <project.reporting.outputEncoding> Utf-8</project.reporting.outputencoding> <java.version>1.8</java.version> </properties> <dependencies> <!--introduce Springboot core package, integrate SPRINGMVC Web Components--<!--implementation principle: Maven relies on inheritance, equivalent to the third party commonly used m Aven dependency information, already encapsulated in the parent project-<dependency> <groupid>org.springframework.boot</groupid& Gt <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--introducing Springboot Test Package--& Gt <dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring- Boot-starter-test</artifactid> <scope>test</scope> </dependency> <!-- Springboot external Tomcat support for compiling JSPs-<dependency> <groupid>org.apache.tomcat.embed</groupi D> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </depend Ency> <!--to join this when fighting a war package, tell Spring-boot tomcat related Jar Pack external, do not enter--<dependency> & Lt;groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-tomcat</art ifactid> <scope>provided</scope> </dependency> </dependencies> < build> <!--Specify the name of the war package, whichever is here, or bring the version number--<finalName>springbootDemo01</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>
3.2 修改完毕,如果你的项目名上出现一个红色的小叉号
请按照进行操作即可
4. Create Springboot Startup class Demoapp.java
Code:
package com.qfx.demo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;/** *
5. Create a ConttollerCode:
package com.qfx.demo.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class UserController { @RequestMapping("getUser") public String getUser(){ return "张三"; }}
6. Compiling the project7. Start Springboot, execute the main method of the DemoApp class8. Test access: Http://127.0.0.1:8080/getUser使用springboot内置tomcat启动,默认省略项目名,端口默认8080,访问结果如,表示启动成功
9. Final attached project complete structureSpringboot get started one, create a new Springboot project with MyEclipse