springspring-bootazurespring-cloudazure-app-configuration

Azure AppConfiguration with Spring Boot 2.5.x


Question

How to integrate an Azure AppConfiguration with SpringBoot 2.5.x or higher?


Info

Im trying to use an Azure AppConfiguration resource with a Spring Boot 2.5.4 project. Unfortunately I cant get it to read a setting from the AppConfiguration or even connect to it as far as I can tell.

The project is newly created with the Spring Initializr where I only added

Afterwards I tried following the Microsoft Quickstart documentation with no success. The documentation mentions that its using Spring 2.4.x so I assume some changes broke it.

I also tried to identify the issue by looking through some Azure Spring Boot Code Samples.

All the examples so far use the bootstrap.properties file which I learned during my search so far is deprecated. Moving the settings to the application.yml or enabling use-legacy-processing: true did not work either. Any ideas?

pom.xml

...
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
...
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>

        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>azure-spring-cloud-appconfiguration-config</artifactId>
            <version>2.0.0</version>
        </dependency>
...

application.yml

spring:
  config:
    use-legacy-processing: true
  profiles:
    active: "develop"
  application:
    name: "MySampleService"
  cloud:
    azure:
      appconfiguration:
        stores:
          - connection-string: "SomeAzureAppConfigurationResourceConnectionString"
            label: ${spring.profiles.active}
#mysampleservice:
#  message: "this is a message from file"

AppConfiguration Resource enter image description here Im not entirely sure about the format for the setting name. I tried to build the format based on this documentation.

The configuration classes should be fine since commenting in the mysampleservice causes the value of message beeing used.

Any hints are appreciated!

Some more info to elaborate on the accepted answer

The documentation linked in the answer refers to two different packages. The one linked right at the start in the maven repository is spring-cloud-azure-appconfiguration-config while the one used further down is azure-spring-cloud-appconfiguration-config. The second one works with the bootstrap.properties file.

Working pom.xml and bootstrap.properties:

...
    <dependencies>
<!--        Dependency to load configuration from azure app configuration resource. Note that additional settings are required in bootstrap.properties
            Documentation of settings: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/appconfiguration/azure-spring-cloud-starter-appconfiguration-config
-->
        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>azure-spring-cloud-appconfiguration-config-web</artifactId>
            <version>2.1.0</version>
        </dependency>
...

# Use this to enable or disable the cloud config, disabling it results in application.yaml beeing used.
spring.cloud.azure.appconfiguration.enabled=true

# Connection string to azure app configuration resource
spring.cloud.azure.appconfiguration.stores[0].connection-string= Endpoint=https://myappconfiguration.azconfig.io;Id=zUcT-l9-s0:PFYfW7WM0/Pz7WZOnH3v;Secret=JTB9myJqGekDAJ5m8Z1vjmkJZrPd88JbO=

# Configured filters for settings in the previous defined app configuration resource
spring.cloud.azure.appconfiguration.stores[0].selects[0].key-filter = /mysampleservice/
spring.cloud.azure.appconfiguration.stores[0].selects[0].label-filter = Sample
spring.cloud.azure.appconfiguration.stores[0].selects[1].key-filter = /notificationservice/
spring.cloud.azure.appconfiguration.stores[0].selects[1].label-filter = Sample2

Solution

  • bootstrap.yml/bootstrap.properties can still be used, they are no longer part of the base Spring packages.

    Also, you want to use this doc for 2.0.0 and newer https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/appconfiguration/azure-spring-cloud-starter-appconfiguration-config.