Generate a Web application template with the following settings in Spring Initializr.
I generated the Packaging items as Jar and War, respectively, and took the difference with the diff command.
$ diff -r jar war
diff -r jar/demo/build.gradle war/demo/build.gradle
4a5
> id 'war'
16a18
> providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
Only in war/demo/src/main/java/com/example/demo: ServletInitializer.java
Gradle War Plugin
Gradle's War Plugin has been added to the War application.
id 'war'
War Plugin is a plugin that adds a task to generate a war file.
Reference: The War Plugin
Spring Boot Tomcat Starter
Spring Boot Tomcat Starter is specified in providedRuntime for War applications.
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
This uses the embedded Tomcat when running in the local environment, but by specifying providedRuntime, the embedded Tomcat is not included when the war file is generated. Reference: Maven Repository: org \ .springframework \ .boot »spring \ -boot \ -starter \ -tomcat
ServletInitializer
A ServletInitializer has been added to the War application.
package com.example.demo;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
}
This will be a class that implements the WebApplicationInitializer interface required in the environment where the war file is deployed and operated. Reference: [SpringBootServletInitializer \ (Spring Boot Docs 2 \ .2 \ .1 \ .RELEASE API )](https://docs.spring.io/spring-boot/docs/2.2.1.RELEASE/api/org/ springframework / boot / web / servlet / support / SpringBootServletInitializer.html)