How to Deploy a Spring Boot WAR to Tomcat Server

In previous post we have learn how to create spring boot project . In this example we create jar file. But some we need deploy spring boot project as war file inside tomcat server. there is steps how to create war file of spring boot application.

1. Extends SpringBootServletInitializer DemoApplication.java

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {

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

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(DemoApplication.class);
}
}

for multiple main class define which main class should start

<properties>
<!-- The main class to start by executing java -jar -->
<start-class>com.javavogue.DemoApplication</start-class>
</properties>

2. Update packaging to war pom.xml

<packaging>war</packaging>

3. Marked the embedded servlet container as provided.  inside pom file.

pom.xml

<!-- marked the embedded servlet container as provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

 

now run maven clean install and war file generated inside target folder.

Leave a Reply

Your email address will not be published. Required fields are marked *

68 − 59 =