[JAVA] Deploy the WEB application by Spring Boot to Tomcat server as WAR

Premise

Added description for war deployment to the class that executes Spring

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(Application.class);
	}

	public static void main(String[] args) throws Exception {
		SpringApplication.run(Application.class, args);
	}

}

Gradle settings and build

Gradle settings

plugins {
	id 'org.springframework.boot' version '2.2.4.RELEASE'
	id 'io.spring.dependency-management' version '1.0.9.RELEASE'
	id 'java'
	id 'war'
}

// ~abridgement~

war {
    enabled = true
    archiveName = 'sample.war'
}

dependencies {
	// ~abridgement~
	providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}

test {
	// ~abridgement~
	exclude 'com/example/demo/ViewTest.class'
}

Build on EC2

Project application.In the directory with properties


$ sudo vim application.properties

application.properties


spring.datasource.url=jdbc:mysql://RDS endpoint:3306/Database name?serverTimezone=JST
spring.datasource.username=******
spring.datasource.password=***********
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.open-in-view=true
#~abridgement~

In the project directory


$ ./gradlew build

Deploy the generated war to tomcat

$ cp sample.war /opt/tomcat-9/webapps/
$ sudo systemctl restart tomcat

If you access it like ↓, the app will run. http://EC2のエンドポイント:8080/sample/作成アプリに応じたリクエスト先

Recommended Posts

Deploy the WEB application by Spring Boot to Tomcat server as WAR
Deploy the application created by Spring Boot to Heroku (public) ②
Deploy the application created by Spring Boot to Heroku (public) ①
Deploy the Spring Boot project to Tomcat on XAMPP
[Java] Deploy the Spring Boot application to Azure App Service
[Spring Boot] Precautions when developing a web application with Spring Boot and placing war on an independent Tomcat server
Sign in to a Spring Boot web application on the Microsoft ID platform
[Spring Boot] Web application creation
I want to bring Tomcat to the server and start the application
Minimal configuration to run Spring Boot application on Azure Web Apps
What to do if the log using JUL is no longer output to the app log after deploying the Spring Boot app to Tomcat as a war
War deploy to Azure Web Apps (maven)
Start web application development with Spring Boot
Run WEB application with Spring Boot + Thymeleaf
Java beginner tried to make a simple web application using Spring Boot
Automatically deploy a web application developed in Java using Jenkins [Spring Boot application]
SameSite cookie in Spring Boot (Spring Web MVC + Tomcat)
What to do if the server tomcat dies
The story of raising Spring Boot 1.5 series to 2.1 series
To manually deploy Struts2 as a war file
[Java / PostgreSQL] Connect the WEB application to the database
I tried to clone a web application full of bugs with Spring Boot
How to set environment variables in the properties file of Spring boot application
Deploy a Spring Boot application on Elastic Beanstalk
Create a web api server with spring boot
Learn while making a WEB server Introduction to WEB application development from the basics
[Spring Boot] How to refer to the property file
A story that stumbled when deploying a web application created with Spring Boot to EC2
Spring Boot application built-in Tomcat, Apache and WebSocket integration
05. I tried to stub the source of Spring Boot
I tried to reduce the capacity of Spring Boot
How to boot by environment with Spring Boot of Maven
Spring Boot 2.3 Application Availability
The story of raising Spring Boot from 1.5 series to 2.1 series part2
Output embedded Tomcat access log to standard output with Spring Boot
About the function of Spring Boot due to different versions
The first WEB application with Spring Boot-Making a Pomodoro timer-
Application file deployment location on the local host Tomcat server
Sample web application that handles multiple databases in Spring Boot 1.5
Create a Spring Boot web app that uses IBM Cloudant and deploy it to Cloud Foundry
Try Spring Boot from 0 to 100.
Introduction to Spring Boot ① ~ DI ~
Introduction to Spring Boot ② ~ AOP ~
CICS-Run Java application-(4) Spring Boot application
Deploy your application to WildFly
Introduction to Spring Boot Part 1
Rails web server and application server
Implement a simple Web REST API server with Spring Boot + MySQL
Let's make a book management web application with Spring Boot part1
Deploy your application to EDAS using the Cloud Toolkit Maven plugin
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
Automatically deploy Web applications developed in Java using Jenkins [Tomcat application]
What I did in the migration from Spring Boot 1.4 series to 2.0 series
[Probably the easiest] WEB application development with Apache Tomcat + Java Servlet
What is the difference between a web server and an application server?
What I did in the migration from Spring Boot 1.5 series to 2.0 series
I want to control the default error message of Spring Boot