This article walks you through deploying an application to Azure Spring Apps.
You are recommended to check out official Azure docs for Azure Spring Apps for the latest instructions for the same task. |
What you’ll build
You’ll clone a sample Spring Boot application from GitHub and then use Maven to deploy it to Azure.
What you’ll need
The following prerequisites are required in order to follow the steps in this article:
-
An Azure subscription. If you don’t already have an Azure subscription, you can sign up for a free Azure account or activate your MSDN subscriber benefits.
-
An up-to-date Java Development Kit (JDK), version 1.8 or later.
-
A Git client.
Build and run a sample Spring Boot web app locally
In this section, you will clone an already written Spring Boot application and test it locally:
-
Open a terminal window.
-
Create a local directory to hold your Spring Boot application by typing
mkdir SpringBoot
-
Change to that directory by typing
cd SpringBoot
. -
Clone the Spring Boot Getting Started sample project into the directory you created by typing
git clone https://github.com/spring-guides/gs-spring-boot
-
Change to the directory of the completed project by typing
cd gs-spring-boot/complete
-
Build the JAR file using Maven by typing
./mvnw clean package
-
When the web app has been created, start it by typing
./mvnw spring-boot:run
-
Test it locally by either visiting http://localhost:8080 or typing
curl http://localhost:8080
from another terminal window. -
You should see the following message displayed: Greetings from Spring Boot!
Config and deploy the app to Azure Spring Apps
-
Before started, you will need to provision an Azure Spring Apps cluster for instance using Azure Portal.
-
From the terminal window, config your web app with Maven Plugin for Azure Spring Apps by typing
./mvnw com.microsoft.azure:azure-spring-cloud-maven-plugin:1.3.0:config
. This maven goal will first authenticate with Azure, if you have logged in with Azure CLI, it will consume its existing authentication token. Otherwise, it will get you logged in with azure-maven-plugin automatically. -
Then you can configure the deployment, run the maven command in the Command Prompt and select the Azure Spring Apps cluster you just created, accept default for app name, then press 'y' to expose public access for this app. When you get the Confirm (Y/N) prompt, press 'y' and the configuration is done.
[email protected]:~/gs-spring-boot/complete$ mvn com.microsoft.azure:azure-spring-cloud-maven-plugin:1.3.0:config [INFO] Scanning for projects... [INFO] [INFO] ----------------------< com.example:spring-boot >----------------------- [INFO] Building spring-boot 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- azure-spring-cloud-maven-plugin:1.3.0:config (default-cli) @ spring-boot --- [INFO] [Correlation ID: xxx] Instance discovery was successful Available Azure Spring Apps Services: 1. xxx* Select Azure Spring Apps for deployment: [1-28] (1): 1 [INFO] Using service: xxx Input the app name (spring-boot): Expose public access for this app spring-boot? (y/N):y Summary of properties: Subscription id : xxx Service name : xxx App name : spring-boot Public access : true Instance count : 1 CPU count : 1 Memory size(GB) : 1 Runtime Java version : Java 8 Confirm to save all the above configurations (Y/n):
-
Optionally, open your pom.xml to see all the configuration written.
<plugin> <groupId>com.microsoft.azure</groupId> <artifactId>azure-spring-cloud-maven-plugin</artifactId> <version>1.3.0</version> <configuration> <subscriptionId>xxx</subscriptionId> <clusterName>xxx</clusterName> <appName>spring-boot</appName> <isPublic>true</isPublic> <deployment> <cpu>1</cpu> <memoryInGB>1</memoryInGB> <instanceCount>1</instanceCount> <runtimeVersion>Java 8</runtimeVersion> <resources> <resource> <filtering/> <mergeId/> <targetPath/> <directory>${project.basedir}/target</directory> <includes> <include>*.jar</include> </includes> </resource> </resources> </deployment> </configuration> </plugin>
-
Once you have configured all of the settings in the preceding sections, you are ready to deploy your web app to Azure Spring Apps with
mvn azure-spring-cloud:deploy
. Maven will deploy your web app to Azure. It might take a few minutes before the web app is accessible at the URL shown in the output. Navigate to the URL in a Web browser. You should see the message displayed: Greetings from Spring Boot! Note that this simple Spring Boot sample app is not using any Spring Cloud components like Discovery Client, thus registration status will be down while the app is up and running normally.
Summary
Congratulations! You built and deployed a Spring Boot app to Azure. You can visit the Azure portal to manage it.
Don’t forget to delete the Azure resources created if no longer needed. |
See also
Additional information about using Spring with Azure is available here:
Want to write a new guide or contribute to an existing one? Check out our contribution guidelines.
All guides are released with an ASLv2 license for the code, and an Attribution, NoDerivatives creative commons license for the writing. |