首页 > 解决方案 > 测试 bootstrap.properties 中的 Spring Boot 2.2.4 未加载包含的 application.properties 配置文件

问题描述

从 2.1.6 升级到 Spring Boot 版本 2.2.4 时,我遇到了问题。

问题场景:

我有一个使用bootstrap-test.proeprtiesand 测试作为活动配置文件的弹簧启动测试。bootstrap-test.properties还包括一些由配置文件定义的其他配置application.properties文件。

下面是示例代码:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT})
@ActiveProfiles("test")
public class SampleTest {

   @Test
    public void sampleTest() {

    }
}


//bootstrap-test.properties

spring.profiles.include=db

application-db.properties此处未加载文件中存在的属性并且测试失败。这在 spring-boot 版本 2.1.x 上运行良好。新靴子有什么变化吗

版本?

如果我将其更改bootstrap-test.propertiesapplication-test.properties. 但是我仍然需要引导文件,因为我有需要在开始时加载的 Spring Cloud Config Server 属性。任何帮助表示赞赏。

标签: spring-boot

解决方案


你用的是什么spring cloud版本?我们在升级到 boot 2.2.4 时也遇到了同样的问题。您应该将 spring cloud 版本升级到Hoxton.SR1boot 2.2.4 。


推荐阅读