【问题标题】:Spring Config Server delivering config file but not activating profilesSpring Config Server 提供配置文件但不激活配置文件
【发布时间】:2022-01-30 19:15:31
【问题描述】:

我有一个配置服务器。 我正在从 2.2 迁移到 2.6,并且我看到属性文件已更改。

我有一个我认为没有涵盖的情况(或者我可能误解了)。

我的情况是我有一个配置服务器来交付:

application.properties --> containing properties shared by every microservices
application-dev.properties --> containing properties specific for dev profile
application-test.properties --> containing properties specific for test profile
application-production.properties --> containing properties specific for production profile
microservicesName.properties --> containing specific properties
microservicesName-mysql.properties --> if I use mysql profile
microservicesName-h2.properties --> if I use h2 profile

在 2.4 之前,我曾经在微服务中放入 application.properties 路径以从配置服务器和配置服务器交付的 application.properties 中获取配置:

spring.profiles.include=dev,mysql

例如,如果我想为所有微服务 dev 和 mysql 激活。

现在,我已将 include 转换为组。例如:

spring.profiles.groups.myConf=dev,mysql

(也尝试使用数组表示法 --> spring.profiles.groups.myConf[0]=dev 和 [1]=mysql) 并添加到每个微服务中

spring.profiles.active=myConf

观察配置服务器日志,它会正确交付配置。我的问题是我有一些用配置文件注释的 Bean,例如:

@Profile('h2')

@Profile('dev')

但这些 bean 未激活且应用程序未启动(也在启动日志配置文件中=[myConf])

我找到的唯一解决方案是在每个微服务 application.properties 中插入

spring.profile.active=dev,mysql

但这看起来不太舒服,因为我有很多微服务。

正确的方法是什么?

P.s.:我也试着不碰任何东西,简单地使用

spring.config.use-legacy-processing=true 

在所有 .properties 中,但没有运气。

【问题讨论】:

    标签: java spring spring-boot spring-cloud


    【解决方案1】:

    几个月后,Spring Boot 2.6.6 和 Spring Framework 5.3.18 解决了这个错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-20
      • 2016-02-27
      • 2011-11-12
      • 2014-10-29
      • 2011-07-17
      • 2015-08-25
      • 1970-01-01
      相关资源
      最近更新 更多