Prepare war package
1、 Prepare the existing springboot project and add dependencies in POM
1) Set the packaging format to war
<packaging>war</packaging>
2) Exclude Tomcat embedded in springboot
<!-- Embedded Tomcat -- > needs to be excluded in the form of war package deployment
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
3) Configure plug-ins
From the original
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
configure
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<!-- Add JVM parameter -- >
<jvmArguments>Dfile.encoding=UTF-8</jvmArguments>
<!-- Specify entry class -- >
<mainClass>com.peko.filemanager.Application</mainClass>
</configuration>
</plugin>
</plugins>
</build>
2、 Configure startup class
From the original
@SpringBootApplication
public class Application{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
configure
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
return builder.sources(Application.class);
}
}
3、 Package with Maven tool
Clean first and then package
After success, you can find the packaged war package in the target folder
Copy it out, and then change the name. Here I change it to HelloWorld war
Tomcat deployed on CentOS
1、 First, install Tomcat
https://blog.csdn.net/piano_diano/article/details/116938060
2、 Upload the war package to Tomcat / webapps using SFTP tool
Restart Tomcat
systemctl restart tomcat
Then open the management interface of Tomcat
You can see that the project is in the startup state. If it is in the shutdown state, go to the log under Tomcat / logs and report any errors
Note: if it is deployed in Tomcat as war, the port number and other information originally configured in the YML file are invalid
HelloWorld project address: https://gitee.com/ShyHour/hello-world
The above is the details of using Tomcat to deploy the war package of springboot in CentOS environment. For more information about using Tomcat to deploy the war package of springboot, please pay attention to other related articles of developeppaer!