Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring @具有动态属性的TestPropertySource_Spring_Spring Mvc_Spring Boot_Spring Test - Fatal编程技术网

Spring @具有动态属性的TestPropertySource

Spring @具有动态属性的TestPropertySource,spring,spring-mvc,spring-boot,spring-test,Spring,Spring Mvc,Spring Boot,Spring Test,我正在使用@TestPropertySource覆盖spring boot应用程序集成测试中的application.yml属性 @TestPropertySource(properties = { "repository.file.path=src/test/resources/x" }) 我想知道是否有办法使属性值动态化。大概是这样的: @TestPropertySource(properties = { "repository.file.path=PropertyValueProvid

我正在使用@TestPropertySource覆盖spring boot应用程序集成测试中的application.yml属性

@TestPropertySource(properties = { "repository.file.path=src/test/resources/x" })
我想知道是否有办法使属性值动态化。大概是这样的:

 @TestPropertySource(properties = { "repository.file.path=PropertyValueProvider.class" })

非常感谢您的反馈。在我的例子中,属性值是特定于系统的,应该在测试运行时生成。

@TestPropertySource
仅提供用于配置
PropertySource
的声明性机制。在Spring参考手册中

如果需要编程支持将
属性源
添加到
环境
,则应实现一个
ApplicationContextInitializer
,可通过
@ContextConfiguration(initializers=…)
注册。在Spring参考手册中

问候,


Sam(SpringTestContext框架的作者)

正确的链接感谢您指出链接已断开。Spring的“当前”文档结构最近发生了变化。所以我已经更新了链接。我发现它可以展示在实践中是如何做到的。@barfuin-这看起来正是我需要的…除了我使用的是Boot v1.5,该示例使用的是2.0中引入的功能(TestPropertyValue)。你不认为有人会有其他的例子吗?在Spring Boot 1.5.x中,你可以使用
@SpringBootTest
属性: