0

问题

如何集成一个Azure AppConfigurationSpringBoot 2.5.x更高?


信息

我试图在项目中使用Azure AppConfiguration资源Spring Boot 2.5.4。不幸的是,据我所知,我无法让它从 AppConfiguration 读取设置,甚至无法连接到它。

该项目是用我只添加的Spring Initializr新创建的

  • Spring Boot Starter Web
  • Spring Boot Starter 安全性
  • Spring Boot Starter WebSocket

之后我尝试按照Microsoft 快速入门文档进行操作,但没有成功。该文档提到它正在使用Spring 2.4.x,所以我认为一些更改破坏了它。

我还尝试通过查看一些Azure Spring Boot Code Samples来确定问题。

到目前为止,所有示例都使用了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>
...

应用程序.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文件一起使用。

工作pom.xmlbootstrap.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
4

1 回答 1

1

bootstrap.yml/bootstrap.properties 仍然可以使用,它们不再是基本 Spring 包的一部分。

此外,您想将此文档用于 2.0.0 和更新版本https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/appconfiguration/azure-spring-cloud-starter-appconfiguration-配置

于 2021-09-20T22:13:18.053 回答