1, pom.xml
<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.shunneng.springboot</groupId> <artifactId>springboot-demo2</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> </project>
2, start the class needs to inherit SpringBootServletInitializer
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; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @SpringBootApplication @Controller public class HelloSpringBoot extends SpringBootServletInitializer{ @RequestMapping("/hello") @ResponseBody publicHello String () { return " Hello springboot " ; } @Override protected SpringApplicationBuilder Configure (SpringApplicationBuilder Builder) { return builder.sources (HelloSpringBoot. Class ); } / * * * springboot execution entry * / public static void main (String [] args) { // SpringApplication.run (HelloSpringBoot.class, args); // no additional promoter may be used provided this line in place SpringApplication file application = new new . SpringApplication (HelloSpringBoot class); // application.setBannerMode(Mode.OFF);//关闭banner application.run(args); } }