Deploy a Spring Boot application to the cloud with Azure App Service

This tutorial will walk you though creating a sample Spring Boot Getting Started web app and deploying it to Azure App Service.

Prerequisites

In order to complete the steps in this tutorial, you need to have the following:

Create the Spring Boot Getting Started web app

The following steps will walk you through the steps that are required to create a simple Spring Boot web application and test it locally.

  1. Open a command-prompt and create a local directory to hold your application, and change to that directory; for example:

    md C:\SpringBoot
    cd C:\SpringBoot
    

    -- or --

    md /users/robert/SpringBoot
    cd /users/robert/SpringBoot
    
  2. Clone the Spring Boot Getting Started sample project into the directory you just created; for example:

    git clone https://github.com/spring-guides/gs-spring-boot.git
    
  3. Change directory to the completed project; for example:

    cd gs-spring-boot
    cd complete
    
  4. Build the JAR file using Maven; for example:

    mvn package
    
  5. Once the web app has been created, change directory to the JAR file and start the web app; for example:

    cd target
    java -jar gs-spring-boot-0.1.0.jar
    
  6. Test the web app by browsing to http://localhost:8080 using a web browser, or use the syntax like the following example if you have curl available:

    curl http://localhost:8080
    
  7. You should see the following message displayed: Greetings from Spring Boot!

    Browse Sample App

Create an Azure web app for use with Java

The following steps will walk you through the steps to create an Azure Web App, configure the required settings for Java, and configure your FTP credentials.

  1. Browse to the Azure portal and log in.

  2. Once you have logged into your account on the Azure portal, click the menu icon for App Services:

    Azure portal

  3. When the App Services page is displayed, click + Add to create a new App Service.

    Create App Service

  4. When the list of web app templates is displayed, click the link for the basic Microsoft Web App.

    Web App Templates

  5. When the information page for the Web App template is displayed, click Create.

    Create Web App

  6. Provide a unique name for your web app and specify any additional settings, and then Create.

    Create Web App Settings

  7. Once your web app has been created, click the menu icon for App Services, and then click your newly-created web app:

    List Web Apps

  8. When your web app is displayed, specify the Java version by using the following steps:

    a. Click the Application Settings menu item.

    b. Choose Java 8 for the Java version.

    c. Choose Newest for the minor Java version.

    d. Choose Newest Tomcat 8.5 for the web container. (This container will not actually be used; Azure will use the container from your Spring Boot application.)

    e. Click Save.

    Application Settings

  9. Specify your FTP deployment credentials by using the following steps:

    a. Click the Deployment Credentials menu item.

    b. Specify your username and password.

    c. Click Save.

    Specify Deployment Credentials

  10. Retrieve your FTP connection information by using the following steps:

    a. Click the Deployment Credentials menu item.

    b. Copy your full FTP username and URL and save them for the next section of this tutorial.

    FTP URL and Credentials

Deploy your Spring Boot web app to Azure

The following steps will walk you through the steps to deploy your Spring Boot web app to Azure.

  1. Open a text editor such as Windows Notepad and paste the following text into a new document, then save the file as 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\gs-spring-boot-0.1.0.jar&quot;">
        </httpPlatform>
      </system.webServer>
    </configuration>
    
  2. After you have saved the web.config file to your system, connect to your web app via FTP using the URL, username, and password from the preceding section of this tutorial. For example:

    ftp
    open waws-prod-sn0-000.ftp.azurewebsites.windows.net
    user wingtiptoys-springboot\wingtiptoysuser
    pass ********
    
  3. Change the remote directory to the root folder of your web app, (which is at /site/wwwroot), then copy the JAR file from your Spring Boot application and the web.config from earlier. For example:

    cd site/wwwroot
    put gs-spring-boot-0.1.0.jar
    put web.config
    
  4. After you have deployed your JAR and web.config files to your web app, you need to restart your web app using the Azure portal:

  5. Test the web app by browsing to your web app's URL using a web browser, or use the syntax like the following example if you have curl available:

    curl http://wingtiptoys-springboot.azurewebsites.net/
    
  6. You should see the following message displayed: Greetings from Spring Boot!

    Browse Sample App

Next steps

For more information about using Spring Boot applications on Azure, see the following articles:

For more information about using Azure with Java, see the Azure for Java Developers and the Java Tools for Visual Studio Team Services.

For additional information about depoying web apps to Azure using FTP, see Deploy your app to Azure App Service using FTP/S.

For further details about the Spring Boot sample project, see Spring Boot Getting Started.

For help with getting started with your own Spring Boot applications, see the Spring Initializr at https://start.spring.io/.

For more information about configuring additional settings for your web app, see Configure web apps in Azure App Service.