Protecting your web APIs and accessing protected APIs like Microsoft Graph to work with your users' and organization's data with Microsoft Entra ID and Azure Active Directory B2C.
The following section demonstrates the benefits of using Spring Cloud Azure. In this section, the retrieval of secrets stored in Azure Key Vault is used as an example. This section compares the differences between developing a Spring Boot application with and without Spring Cloud Azure.
Without Spring Cloud Azure
Without Spring Cloud Azure, if you want to retrieve secrets stored in Azure Key Vault, you need to the following steps:
Add the following dependencies to your pom.xml file:
If you're using Spring Boot 2.x, be sure to set the spring-cloud-azure-dependencies version to 4.19.0.
This Bill of Material (BOM) should be configured in the <dependencyManagement> section of your pom.xml file. This ensures that all Spring Cloud Azure dependencies are using the same version.
For more information about the version used for this BOM, see Which Version of Spring Cloud Azure Should I Use.
Add the following properties to your application.yml file:
spring:
cloud:
azure:
keyvault:
secret:
endpoint:
Sign in with Azure CLI by using the following command. Your credentials will then be provided by Azure CLI, so there will be no need to add other credential information such as client-id and client-secret.
az login
Auto-wire SecretClient in the relevant places, as shown in the following example:
@SpringBootApplication
public class SecretClientApplication implements CommandLineRunner {
private final SecretClient secretClient;
public SecretClientApplication(SecretClient secretClient) {
this.secretClient = secretClient;
}
public static void main(String[] args) {
SpringApplication.run(SecretClientApplication.class, args);
}
@Override
public void run(String... args) {
System.out.println("sampleProperty: " + secretClient.getSecret("sampleProperty").getValue());
}
}
Spring Cloud Azure will provide some other features besides the auto-configured SecretClient. For example, you can use @Value to get the secret value, as shown in the following example:
@SpringBootApplication
public class PropertySourceApplication implements CommandLineRunner {
@Value("${sampleProperty1}")
private String sampleProperty1;
public static void main(String[] args) {
SpringApplication.run(PropertySourceApplication.class, args);
}
public void run(String[] args) {
System.out.println("sampleProperty1: " + sampleProperty1);
}
}
Components of Spring Cloud Azure
Azure support
Provides auto-configuration support for Azure Services, such as Service Bus, Storage, Active Directory, and so on.
Provides Spring @Value annotation support for integration with Azure Key Vault Secrets. For more information, see Spring Cloud Azure secret management.
If you need support for Spring Cloud Azure, you can ask for help in the following ways:
Create Azure support tickets. Customers with an Azure support plan can open an Azure support ticket. We recommend this option if your problem requires immediate attention.
Start here and learn how you can get the full power of Azure with your Java apps - use idiomatic libraries to connect and interact with your preferred cloud services, including Azure SQL and NoSQL databases, messaging and eventing systems, Redis cache, storage and directory services. As always, use tools and frameworks that you know and love – Spring, Tomcat, WildFly, JBoss, WebLogic, WebSphere, Maven, Gradle, IntelliJ, Eclipse, Jenkins, Terraform and more.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.