具有动态属性的@TestPropertySource

问题描述 投票:8回答:1

我正在使用@TestPropertySource覆盖我的集成测试中的application.yml属性,以用于Spring启动应用程序。

@TestPropertySource(properties = { "repository.file.path=src/test/resources/x" })

我想知道是否有某种方法可以使属性VALUE动态化。像这样的东西:

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

感谢您的反馈。在我的情况下,属性值是系统特定的,应该在测试运行时生成。

spring spring-mvc spring-boot spring-test
1个回答
12
投票

@TestPropertySource仅提供用于配置PropertySources的声明性机制。 “参考手册”中的Documentation

如果你需要编程支持将PropertySource添加到Environment,你应该实现一个可以通过ApplicationContextInitializer注册的@ContextConfiguration(initializers = ...)。 “参考手册”中的Documentation

问候,

Sam(Spring TestContext Framework的作者)

© www.soinside.com 2019 - 2024. All rights reserved.