Guest yorkzhang Posted January 11, 2023 Posted January 11, 2023 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). 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... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.