Unit testing 如何使用@TestPropertySource在单元测试中重写@ConfigurationProperties配置类中使用的@PropertySource中的配置值

Unit testing 如何使用@TestPropertySource在单元测试中重写@ConfigurationProperties配置类中使用的@PropertySource中的配置值,unit-testing,spring-boot,Unit Testing,Spring Boot,我有一个前缀为“资产”的配置属性实例 其默认配置在中定义: @Configuration @PropertySource( name = "assetsConfig", value = "classpath:com/package/boot/web/ui/assets/config/default-assets-config.properties" ) @Order( LOW_ORDER ) public class AssetsConfig { } d

我有一个前缀为“资产”的配置属性实例

其默认配置在中定义:

@Configuration
@PropertySource( name = "assetsConfig", value = "classpath:com/package/boot/web/ui/assets/config/default-assets-config.properties" )
@Order( LOW_ORDER )
public class AssetsConfig
{
}
default-assets-config.properties包含:

assets.file=classpath:assets.json
在我的单元测试中,我希望使用以下命令覆盖默认值:

@TestPropertySource( locations = "classpath:com/package/boot/web/ui/assets/tests/assets-config.properties" )
assets-config.properties包含

assets.file=classpath:com/package/boot/web/ui/assets/tests/assets.json
不幸的是,此值从未注入AssetProperties。 我做错了什么,我不明白,因为

测试属性源的优先级高于从操作系统环境或Java系统属性以及应用程序通过@PropertySource或编程方式声明添加的属性源加载的属性源

提前感谢,

Paskos

您遇到了一个问题,这意味着它忽略了使用
@TestPropertySource
配置的属性文件。或者,您可以配置一个或多个内联属性:

@TestPropertySource(properties = "assets.file=classpath:com/package/boot/web/ui/assets/tests/assets.json")

谢谢你,安迪。我订阅了这个问题,我将在等待时使用内联属性。升级到spring boot 1.2.3,现在就可以使用了。谢谢
@TestPropertySource(properties = "assets.file=classpath:com/package/boot/web/ui/assets/tests/assets.json")