在 Spring Boot 中使用外部化配置进行 junit 测试的不同 YAML 配置文件
Different YAML configuration file for junit test using an Externalized configuration in Spring Boot
我正在关注 tutorial 将外部配置文件用于 Spring Boot。我让一切都按预期工作,但我在覆盖测试的默认 YAML 配置时遇到问题。
如果使用“@PropertySource”是将配置文件加载到项目中的最佳方式,有人能给我指出正确的方向或建议吗(有很多属性,我想保留 application.yaml尽可能干净)
项目结构:
src: - main/resources/foo.yml <-- always loads this one
- test/resources/foo.yml <-- never loads
我试过的:
@PropertySource(value = "classpath:foo.yml")
不加载 test/resoruces/foo.yml 到类路径
ActiveProfiles()
我通常如何更改配置属性,但在这种情况下,它不是配置文件,所以它不起作用。
详情:
Spring 开机:2.2.7.RELEASE
试试这个:
@TestPropertySource(properties = { "spring.config.location=classpath:foo.yml" })
我正在关注 tutorial 将外部配置文件用于 Spring Boot。我让一切都按预期工作,但我在覆盖测试的默认 YAML 配置时遇到问题。
如果使用“@PropertySource”是将配置文件加载到项目中的最佳方式,有人能给我指出正确的方向或建议吗(有很多属性,我想保留 application.yaml尽可能干净)
项目结构:
src: - main/resources/foo.yml <-- always loads this one
- test/resources/foo.yml <-- never loads
我试过的:
@PropertySource(value = "classpath:foo.yml")
不加载 test/resoruces/foo.yml 到类路径
ActiveProfiles()
我通常如何更改配置属性,但在这种情况下,它不是配置文件,所以它不起作用。
详情:
Spring 开机:2.2.7.RELEASE
试试这个:
@TestPropertySource(properties = { "spring.config.location=classpath:foo.yml" })