Jump to content

Deploy Spring boot application to App Service Tomcat Stack using generated war file


Recommended Posts

Guest yorkzhang
Posted

Some people usually choose to follow this document to package the Spring Boot application to a jar file and use cli command to deploy the jar file to the app service with Java SE stack. However, you may also choose to package the Spring Boot project to a war file and deploy it to Tomcat. This article shows how you can do it.

 

Firstly, you need to modify your Spring Boot application entrance class to entend SpringBootServletInitializer class and override configure method:

 

 

 

 

 

 

 

 

 

@SpringBootApplication

public class DemoApplication extends SpringBootServletInitializer {

@Override

protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {

return application.sources(DemoApplication.class);

}

 

public static void main(String[] args) {

SpringApplication.run(DemoApplication.class, args);

}

}

 

 

 

 

 

 

 

 

 

You also need to make sure your project will be package to a war file. In Maven, it is specified in packaging element in the pom.xml:

 

 

 

 

 

 

 

 

 

<packaging>war</packaging>

 

 

 

 

 

 

 

 

 

If you are using Gradle, modify build.gradle as below:

 

 

 

 

 

 

 

 

 

apply plugin: 'war'

 

 

 

 

 

 

 

 

 

You also need to have the following text in Maven to mark the embedded servlet container dependency as provided:

 

 

 

 

 

 

 

 

 

<dependencies>

<!-- … -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-tomcat</artifactId>

<scope>provided</scope>

</dependency>

<!-- … -->

</dependencies>

 

 

 

 

 

 

 

 

 

If you are using Gradle:

 

 

 

 

 

 

 

 

 

dependencies {

// …

providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'

// …

}

 

 

 

 

 

 

 

 

 

Then run "mvn clean" in the project folder or rebuild grade to generate the war file.

 

You can then create a web app and choose the same Tomcat version as the embedded one of your Spring Boot project. (Currently Tomcat 10 is not supported for Springboot yet).

 

mediumvv2px400.png.0e1a99ef3228381f43129925dc89fd61.png

 

Once it is created, run below command to deploy the war file to the app service:

 

 

 

 

 

 

 

 

 

az webapp deploy --resource-group <group-name> --name <app-name> --src-path ./<package-name>.war

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...