How To deploy Spring Boot application on Tomcat? - CodeByAkram

How To deploy Spring Boot application on Tomcat?

How To deploy Spring Boot application on existing Tomcat?

Related Questions:- Deploy a Spring Boot WAR into a Tomcat Server, Spring Boot – Deploy WAR file to Tomcat

spring boot tomcat codybyakram


Spring boot is a framework that allow you to set up production ready setup of spring application and also Tomcat is one of the most popular server used for Java. By default spring boot application build a standalone application that can contains the Tomcat. But if you have your existing Tomcat and you want to deploy your spring boot application on that server than you need to follow the below steps.

Add the below dependency in pom.xml

               <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

And change the packaging to war or just add the below code in pon.xml.

             <packaging>war</packaging>

Finally, we initialize the Servlet context required by Tomcat by implementing the SpringBootServletInitializer interface and override the configure method:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);

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

}
}

Now build war file using below maven command,
      
      mvn clean package

No comments:

Post a Comment