The Springboot project is a simple thing to publish to the server, but there are some potholes that need to be noticed in the Tomcat container that is posted to the Docker boot on the server.
Here's a complete introduction: Publish the Springboot Web project to the Tomcat container that is launched in Docker.
Spring Project Publishing, refer to: Docker---(3) Docker Publish Spring Web project
Springboot Introduction, please refer to: springboot--starting from 0 to learn Springboot
Docker to get started, please refer to: Docker---Learn from zero docker
1.pom.xml
Change the package mode to war package
[Java] view plain copy <packaging>war</packaging> remove springboot built-in tomcat, add Servlet-api
[Java] View Plain copy <dependency> <groupId> org.springframework.boot</groupid> <artifactId> spring-boot-starter-web</artifactid> <!--Remove the built-in tomcat--> <exclusions> <exclusion> < groupid>org.springframework.boot</groupid> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </ exclusions> </dependency> <!--add servlet-api--> <dependency > <groupid>org.apache.tomcat</groupid> <artifactId> tomcat-servlet-api</artifactid> <version>8.0.36</version> <scope>provided</scope> </dependency> Add Project Access path to build[Java]View Plain Copy <finalName>tweb</finalName>
(When I first published, I read 30 articles, did not mention this, published more than 20 times did not succeed)
[Java] view plain copy <build> <!--packaged Project Access name--> <finalname>tweb</finalname> ; <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </b Uild> 2. Customize a Servletinitializer class that inherits Springbootservletinitializer to start the context
(and start class directory siblings)
[Java] View plain copy package com.jd; import org.springframework.boot.autoconfigure.enableautoconfiguration; import org.springframework.boot.builder.springapplicationbuilder; import org.springframework.boot.web.support.springbootservletinitializer; import org.springframework.context.annotation.componentscan; import org.springframework.context.annotation.configuration; /** * Date 2018/1/30 * description: Start spring's context */