首页 > 解决方案 > 在测试 Spring Boot 中加载不同的 application.yml

问题描述

我有一个问题,我无法在主要测试中加载 YML。我目前在路径中有一个application.ymlsrc > main > resources > config > application.yml,我希望它采用src > test > resources > config > application-test.yml

我已经尝试过使用@ActiveProfiles("test"),但走主要路线。我也试过@Profile("test"),但没有什么不同。

我还尝试简单地在路径中创建application.ymlsrc > test > resources > config > application.yml

还要放注解:

@SpringBootTest(
        properties = ["spring.profiles.active=test"],
        classes = Application.class,
)

任何人都知道如何解决这个问题?

标签: springspring-bootunit-testingyaml

解决方案


推荐阅读