Deploying Springboot to Azure App Service

I'm trying to deploy my springboot project into Azure App Service. I created an App Service and uploaded via FTP two files: test.war and web.config as mentioned in their tutorials.

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
        arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar   &quot;%HOME%\site\wwwroot\test.war&quot;">
    </httpPlatform> 
  </system.webServer>
</configuration>

I'm uploading the war file into the site/wwwroot and placed the web.config file there as well.

My question is: How do I execute the war file? is it supposed to happen when I finish deploy automatically? cause right now all I get is Service Unavailable, Http Error 503.

Thanks


Solution 1:

@ItaiSoudry, According to the content of your web.config file, it seems that you want to use the embedded servlet container like embedded tomcat or jetty to start up the spring boot web application.

Assumption that the IDE you used is Eclipse, you need to export your spring boot project as a runnable jar file, not a war file, please see the figure below.

enter image description here

enter image description here

Note: The Launch configuration should be selected the Class which the main function contains SpringApplication.run.

Meanwhile, you need to configure the listen port with %HTTP_PLATFORM_PORT% the Azure App service supported via the argument --server.port=%HTTP_PLATFORM_PORT% in the web.config file or set the port of the class ServerProperties with the value System.getenv("HTTP_PLATFORM_PORT").

Here is a sample for web.config with --server.port=%HTTP_PLATFORM_PORT%.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
        arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\test.jar&quot;">
    </httpPlatform>
  </system.webServer>
</configuration>

If you want to deploy a war file, you need to configure the ApplicationSettings of your app service on Azure portal, then upload the war file into the path wwwroot/webapps.

enter image description here

As references, please refer to the documents below.

  1. The Springboot subsection in the article https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/#application-configuration-examples
  2. Create a Java web app in Azure App Service

Hope it helps.