Use tomcat to deploy SpringBoot war package in centos environment

Use tomcat to deploy SpringBoot war package in centos environment

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 the tomcat embedded in SpringBoot

 <!-- When deploying in war package, you need to exclude the embedded tomcat -->
		<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 plugin

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 parameters -->
					<jvmArguments>Dfile.encoding=UTF-8</jvmArguments>
					<!-- Specify the entry class -->
					<mainClass>com.peko.filemanager.Application</mainClass>
				</configuration>
			</plugin>
		</plugins>
	</build>

2. Configure the 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. Packaging with Maven Tools

Clean first, then package

After success, you can find the packaged war package in the target folder

Copy it and then change the name. Here I changed it to helloworld.war

Deploy to tomcat on centos

1. First, install tomcat

https://blog.csdn.net/piano_diano/article/details/116938060

2. Upload the war package to tomcat/webapps using the sftp tool

Restart tomcat

systemctl restart tomcat

Then open the tomcat management interface

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 to see what error is reported.

Note: If the war file is deployed in tomcat, the port number and other information originally configured in the yml file will be invalid.

helloworld project address: https://gitee.com/ShyHour/hello-world

The above is the details of using tomcat to deploy SpringBoot's war package in the centos environment. For more information about tomcat deploying SpringBoot's war package, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Springboot multi-module multi-environment configuration file problem (dynamic configuration of production and development environment)
  • Detailed steps for building an SSM development environment based on SpringBoot in IntelliJ IDEA
  • SpringBoot environment configuration knowledge summary
  • Clever use of profiles in springboot yml (multi-environment configuration for beginners)
  • Tutorial on deploying springboot package in linux environment using docker
  • Detailed explanation of SpringBoot+docker environment variable configuration
  • Detailed tutorial on building a springboot selenium web page file to image environment
  • Springboot multi-environment switching method
  • SpringBoot environment construction and first program running (novice tutorial)
  • Matplotlib visualization custom colors to draw beautiful statistical graphs

<<:  Modify the style of HTML body in JS

>>:  The concept and characteristics of MySQL custom variables

Recommend

Detailed explanation of keepAlive usage in Vue front-end development

Table of contents Preface keep-avlive hook functi...

How to add vim implementation code examples in power shell

1. Go to Vim's official website to download t...

IIS configuration of win server 2019 server and simple publishing of website

1. First remotely connect to the server 2. Open S...

MySQL 5.7.21 installation and configuration tutorial under Window10

This article records the installation and configu...

MySQL uses SQL statements to modify table names

In MySQL, you can use the SQL statement rename ta...

How to quickly build an FTP file service using FileZilla

In order to facilitate the storage and access of ...

Example of how to change the domestic source in Ubuntu 18.04

Ubuntu's own source is from China, so the dow...

MySQL method steps to determine whether it is a subset

Table of contents 1. Problem 2. Solution Option 1...

Solution to Incorrect string value in MySQL

Many friends will report the following error when...

How to use Typescript to encapsulate local storage

Table of contents Preface Local storage usage sce...

Detailed explanation of gcc command usage under Linux system

Table of contents 1. Preprocessing 2. Compilation...

How to deploy FastDFS in Docker

Install fastdfs on Docker Mount directory -v /e/f...

Detailed explanation of the process of docker packaging Python environment

The steps of docker packaging Python environment ...

Detailed explanation of the usage of 5 different values ​​of CSS position

The position property The position property speci...