Monday, September 9, 2019

Deploy spring boot web application in Azure as App Service

Deploy spring boot web application in Azure as App Service


  1. https://www.youtube.com/watch?v=7gJVMzfjHpQ

Spring Boot WAR file is not working after tomcat deployment in Microsoft azure:

Jar is working fine. But if I create war file, then it is not working.

For Maven Users:
================


for creating war file, I need to change the following.

1. In pom.xml file, add [packaging] tag file.
<packaging>war</packaging>

2. Add start-class in properties section of pom.xml file
<properties>     
    <start-class>mypackage.App</start-class>
</properties>

3. Main Application class should look like below:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    /**
     * Used when run as JAR
     */
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
    /**
     * Used when run as WAR
     */
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
    }
}
Resource Link:


  1. https://stackoverflow.com/a/39445027


For Gradle Users:


1. Add plugin to build.gradle

apply plugin: 'war'

2. Add provided dependency to tomcat

dependencies {
    // other dependencies
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}