问题
如何将Azure AppConfiguration与SpringBoot 2.5.x或更高版本集成?
信息
我试图在Azure AppConfiguration项目中使用Spring Boot 2.5.4资源。不幸的是,我无法让它从AppConfiguration读取一个设置,甚至无法根据我所能知道的来连接到它。
该项目是新创建的弹簧起爆,其中我只添加了
之后,我试着跟踪Microsoft Quickstart文档,但没有成功。文档提到它使用Spring 2.4.x,所以我假设一些更改破坏了它。
我还试图通过一些Azure弹簧启动代码示例来识别这个问题。
到目前为止,我在搜索过程中学到的所有示例都使用了bootstrap.properties文件。将设置移动到application.yml或启用use-legacy-processing: true也不起作用。有什么想法吗?
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资源

我不完全确定设置名称的格式。我试图构建基于这份文件的格式。
配置类应该是可以的,因为在mysampleservice中的注释会导致所使用的消息的值。
任何提示都是非常感谢的!
关于被接受的答案的更多信息
答案中链接的文档指的是两个不同的包。在maven存储库中开始链接的是spring-cloud-azure-appconfiguration-config,而下面使用的是azure-spring-cloud-appconfiguration-config。第二种方法处理bootstrap.properties文件。
Working 和 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发布于 2021-09-20 22:13:18
can /bootstrap.properties仍然可以使用,它们不再是基本Spring包的一部分。
另外,您希望将这个文档用于2.0.0和更新的https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/appconfiguration/azure-spring-cloud-starter-appconfiguration-config。
https://stackoverflow.com/questions/69258678
复制相似问题