以前我们的应用程序基于 springboot 2.2.2 版,我们的测试之一是使用 aws
覆盖 @ActiveProfiles("test")
文件中的 SPRING_PROFILES_ACTIVE
属性配置。一切正常。
application.xml
但是我们把springboot升级到2.4.2版本后就不行了,在我们的测试中只能把spring.profiles.active读成空字符串,而以前是可以读作字符串“test”。
springboot 2.4.2版本的@ActiveProfiles注解应该怎么做?非常感谢。
答案 0 :(得分:4)
您受到 Spring Boot issue 19537 修复程序的影响。为了修复名称中带有逗号的支持配置文件,活动配置文件现在被设置为单独的索引属性。例如,如果您激活配置文件 a
、b,c
和 d
,将设置三个属性:
spring.profiles.active[0]=a
spring.profiles.active[1]=b,c
spring.profiles.active[2]=d
在此修复之前,spring.profiles.active
将设置为 a,b,c,d
,这将导致 4 个配置文件处于活动状态:a
、b
、c
和d
。
我建议您查看正在查看 spring.profiles.active
属性的代码。直接访问属性的值是相当不寻常的。更典型的方法是在 getActiveProfiles()
上调用 Environment
。