gpt4 book ai didi

spring - 具有动态属性的@TestPropertySource

转载 作者:行者123 更新时间:2023-12-03 15:30:13 25 4
gpt4 key购买 nike

我在 Spring Boot 应用程序的集成测试中使用 @TestPropertySource 覆盖 application.yml 属性。

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

我想知道是否有某种方法可以使属性 VALUE 动态化。像这样的东西:
 @TestPropertySource(properties = { "repository.file.path=PropertyValueProvider.class" })

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

最佳答案

@TestPropertySource仅提供声明机制来配置 PropertySource s。 Documentation在 Spring 引用手册中。

如果您需要编程支持来添加 PropertySourceEnvironment ,你应该实现一个 ApplicationContextInitializer可以通过@ContextConfiguration(initializers = ...)注册. Documentation在 Spring 引用手册中。

问候,

Sam(Spring TestContext 框架的作者)

关于spring - 具有动态属性的@TestPropertySource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33855874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com