Spring Boot Deployment On Azure App Service — Zero Code Approach

Okezie Arukwe
6 min readApr 8, 2019

--

When I finally decided it’s time for my Spring Boot app to go live, my first choice for a hosting platform was Azure (I have my reasons). And naturally first thing I did was to google “how to deploy spring boot app to azure”.

I was initially excited at the number of results I found on this topic, until I saw none of the guides actually gave me exactly what I needed. They all seemed either outdated or too technical to be practical and always required installing other tools like azure-cli and maven and executing some command sequences.

After a lot of search and some trials and errors, I finally got exactly what I was looking for: a stress free, code free, deployment flow for simple spring boot apps on azure app service. In this very short article I am going to share this knowledge with you.

Note that this guide proceeds with the following basic assumptions about your technical knowledge:

  • You are familiar with spring boot.
  • You are familiar with source control and git.
  • You know your way around azure portal.

Step 1: Build Your Spring Boot App

First step towards deploying your spring boot app on azure should be to create and build said app. For the purpose of this guide, you can use your existing app, create a new app on start.spring.io, or clone or fork this hello world app from github: https://github.com/k32yr04n/hello-azure.

Run mvn package on the app’s root folder to package your app into an executable fat jar ready for deployment. You can verify the app is working locally by running mvn spring-boot:run and navigating to the app’s URL:PORT on a browser.

The app is working locally.

Step 2: Create a web.config file

To run the application on azure, a web.config is required. below is a sample generic web.config file for an azure app. note that the application’s jar name in this case is hello-azure-0.0.1-SNAPSHOT.jar, you should not forget to replace that with the file name for your own executable jar if necessary.

Azure spring boot web.config file sample

Step 3: Create a Deployment Repository

Azure App Service provides a number of deployment options. In our own case, the simplest options among these are FTP/SFTP or via Source Control. In this guide we will use source control which I found to be the easiest.

So next you create a repository (bitbucket or github will do) for your application’s source code. Then create a branch on the repository for deployment. Remove all source files from the deployment branch and place the already built executable jar there together with the web.config file from step 2 above. Then add and commit these files and push to the remote repository.

Master branch
Deploy branch

Step 4: Create & Configure Azure App

Now logon to azure portal and create a new API App. Just search for API App in the new app pane and click on create to create your app.

Create new web app

Once your app is ready, go to the application settings page and make the following changes:

  • Change Java version from Off to Java 8 or any other version of java you are using.
  • Change Java minor version to Auto-Update.
  • Change Java web container to Tomcat 9.0 (Auto Update) or the corresponding version in your case.
  • Also change Platform to 64-bit and Always On to On.
Configure your app for java

Next go to App Service Editor (Preview) and click on Go to open up the app service editor window. Then delete all files and folders present under the wwwroot folder.

Open App Service Editor
Delete all those files and folders

Step 5: Set Up Deployment Pipeline

For the final step of this process, go to Deployment Center and select GitHub for source control (or wherever your repository is hosted — there are several options available including BitBucket, FTP, and locally hosted repositories). Then click on authorize. A window will popup where you click a button to authorize AzureAppService to access your GitHub repositories. You might be required to login to GitHub to complete this step.

After authorization, click on Continue. Then select App Service Kudu Build Server and click Continue. On the next page you will choose your repository details and click on continue

Choose App Service kudu build server
Select your github username/organization, repository and deployment branch
Review your settings and finish

When you click on Finish, azure will configure your deployment, then connect to your repository to fetch your app from the specified branch.

Deployment Successful

If you go back to the App Service Editor page, you should now see only your spring boot jar file and the web.config file present.

Successful Deployment

You can now go to the application overview page on azure to see the app details including the URL which you can follow to navigate to your app. The URL is in the following format: https://<your-app-name>.azurewebsites.net

Application’s Overview Page
CONGRATULATIONS!!! YOUR APP IS LIVE!

Final Step:

That’s it! Your Spring Boot application is now live on Azure App Service.

Note that the app will be auto-updated / redeployed once azure notices a new commit to your deployment branch.

So to update your application, simply rebuild and update the jar file in the deploy branch and push to source control (GitHub).

You can go ahead and set a custom domain name for your app and even Enable Free SSL on your new domain to improve security.

Congratulations! You’ve made it to the end of this post!

If you like this post or find it interesting please don’t hesitate to give it a clap or two or three, you know you can just keep clapping, I’ll appreciate. Also feel free to share it!

You can also check out my other posts on Deploying Spring Boot applications as Windows Services and Securing Your Azure App With SSL for free.

--

--