The method of packaging springboot into war and deploying to tomcat container
This article mainly explains "the method of deploying springboot into war to tomcat container". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "the method of deploying springboot into war to tomcat container" together!
Step 1: Modify pom.xml to add war
Step 2: Remove tomcat components
org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat
Step 3: introduce servletjar, tomcat related jar
javax.servlet javax.servlet-api 3.1.0 provided org.apache.tomcat tomcat-servlet-api 8.0.36 provided
Step 4: Note that finalName is the name of the project.
org.springframework.boot spring-boot-maven-plugin demo
Step 5: Modify the startup class
import org.springframework.boot.SpringApplication;import org.springframework.boot. autofigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.support.SpringBootServletInitializer;@SpringBootApplication //spring boot startup public class StartApp extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(StartApp.class); } public static void main(String[] args) { SpringApplication.run(StartApp.class, args); }}
Step 6: Use the maven command mvn clean package to package into war
Then drop war into the webapp directory and start tomcat
Note: modify your tomcat port number oh, the port number configured in the original project configuration file is invalid.
Start tomcat access
Thank you for reading, the above is the "springboot packaged into war deployment to tomcat container method" content, after learning this article, I believe that we have a deeper understanding of the springboot packaged into war deployment to tomcat container method, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!