Prepare an application for deployment in Azure Spring Apps
Note
The Basic, Standard, and Enterprise plans will be deprecated starting from mid-March, 2025, with a 3 year retirement period. We recommend transitioning to Azure Container Apps. For more information, see the Azure Spring Apps retirement announcement.
The Standard consumption and dedicated plan will be deprecated starting September 30, 2024, with a complete shutdown after six months. We recommend transitioning to Azure Container Apps.
Note
Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.
This article shows how to prepare an existing Java Spring application for deployment to Azure Spring Apps. If configured properly, Azure Spring Apps provides robust services to monitor, scale, and update your Java Spring application.
Before running this example, you can try the basic quickstart.
Other examples explain how to deploy an application to Azure Spring Apps when the POM file is configured.
This article explains the required dependencies and how to add them to the POM file.
Java Runtime version
For details, see the Java runtime and OS versions section of the Azure Spring Apps FAQ.
Spring Boot and Spring Cloud versions
To prepare an existing Spring Boot application for deployment to Azure Spring Apps, include the Spring Boot and Spring Cloud dependencies in the application POM file as shown in the following sections.
Azure Spring Apps supports the latest Spring Boot or Spring Cloud major version starting from 30 days after its release. Azure Spring Apps supports the latest minor version as soon as it's released. You can get supported Spring Boot versions from Spring Boot Releases and Spring Cloud versions from Spring Cloud Releases.
The following table lists the supported Spring Boot and Spring Cloud combinations:
Spring Boot version | Spring Cloud version | End of support |
---|---|---|
3.2.x | 2023.0.x also known as Leyton | 2024-11-23 |
3.1.x | 2022.0.3+ also known as Kilburn | 2024-05-18 |
3.0.x | 2022.0.3+ also known as Kilburn | 2023-11-24 |
2.7.x | 2021.0.3+ also known as Jubilee | 2023-11-24 |
For more information, see the following pages:
- Version support for Java, Spring Boot, and more
- Spring Boot support
- Spring Cloud Config support
- Spring Cloud Netflix support
- Adding Spring Cloud To An Existing Spring Boot Application
Other recommended dependencies to enable Azure Spring Apps features
To enable the built-in features of Azure Spring Apps from service registry to distributed tracing, you need to also include the following dependencies in your application. You can drop some of these dependencies if you don't need corresponding features for the specific apps.
Service Registry
To use the managed Azure Service Registry service, include the spring-cloud-starter-netflix-eureka-client
dependency in the pom.xml file as shown here:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
The endpoint of the Service Registry server is automatically injected as environment variables with your app. Applications can register themselves with the Service Registry server and discover other dependent applications.
EnableDiscoveryClient annotation
Add the following annotation to the application source code.
@EnableDiscoveryClient
For example, see the piggymetrics application from earlier examples:
package com.piggymetrics.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
Distributed configuration
To enable distributed configuration, include the following spring-cloud-config-client
dependency in the dependencies section of your pom.xml file:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
Warning
Don't specify spring.cloud.config.enabled=false
in your bootstrap configuration. Otherwise, your application stops working with Config Server.
Metrics
Include the spring-boot-starter-actuator
dependency in the dependencies section of your pom.xml file as shown here:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Metrics are periodically pulled from the JMX endpoints. You can visualize the metrics by using the Azure portal.
Warning
You must specify spring.jmx.enabled=true
in your configuration property. Otherwise, metrics can't be visualized in the Azure portal.
See also
- Analyze application logs and metrics
- Set up your Config Server
- Spring Quickstart Guide
- Spring Boot documentation
Next steps
In this article, you learned how to configure your Java Spring application for deployment to Azure Spring Apps. To learn how to set up a Config Server instance, see Set up a Config Server instance.
More samples are available on GitHub: Azure Spring Apps Samples.