首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有SpringBoot2.5.x的Azure AppConfiguration

带有SpringBoot2.5.x的Azure AppConfiguration
EN

Stack Overflow用户
提问于 2021-09-20 17:38:07
回答 1查看 1.3K关注 0票数 1

问题

如何将Azure AppConfigurationSpringBoot 2.5.x或更高版本集成?

信息

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

该项目是新创建的弹簧起爆,其中我只添加了

  • 弹簧启动网
  • 弹簧启动安全性
  • 弹簧启动器WebSocket

之后,我试着跟踪Microsoft Quickstart文档,但没有成功。文档提到它使用Spring 2.4.x,所以我假设一些更改破坏了它。

我还试图通过一些Azure弹簧启动代码示例来识别这个问题。

到目前为止,我在搜索过程中学到的所有示例都使用了bootstrap.properties文件。将设置移动到application.yml或启用use-legacy-processing: true也不起作用。有什么想法吗?

pom.xml

代码语言:javascript
复制
...
    <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

代码语言:javascript
复制
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**:**

代码语言:javascript
复制
...
    <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>
...
代码语言:javascript
复制
# 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
代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69258678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档