Home > Software engineering >  Azure AppConfiguration with Spring Boot 2.5.x
Azure AppConfiguration with Spring Boot 2.5.x

Time:09-21

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 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://myofficeconfiguration.azconfig.io;Id=zUcT-l9-s0:PFYfW7WM0/Pz7WZOnH3v;Secret=JTB9myJqGekDAJ5m8Z1vjmkJZrPd88JbOEE3EqoqJYs=

# 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

CodePudding user response:

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.

  • Related