【问题标题】:SpringBoot not resolving devtools properties in testsSpring Boot 无法解析测试中的 devtools 属性
【发布时间】:2023-04-11 06:25:01
【问题描述】:

我将 spring-boot-devtools 与我的 SpringBoot 应用程序 (2.2.8) 一起使用,以在我的存储库之外存储秘密。这适用于正在运行的应用程序,但集成测试因Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'secret.key' in value "${secret.key}" 而失败。

SecretController.kt

@RestController
class SecretController(
        @Value("\${secret.key}") private val secret: String
) {

    @GetMapping("/secret")
    fun secret(): String {
        return secret
    }
}

.spring-boot-devtools.properties

secret.key: secret-asdf

在较旧的应用程序(SpringBoot 2.1)中,这可以正常工作。我知道他们changed the path with SpringBoot 2.2,但kept the old path as backwards compatibility - 我都试过了,但都没有成功。我也升级到 2.3.1,但这也无济于事。

关于如何使用 SpringBoot >= 2.2 读取集成测试中的属性有什么想法吗?

【问题讨论】:

  • 似乎是 spring boot 中的一个错误... spring boot 2.1 对我来说很好。

标签: spring-boot integration-testing devtools


【解决方案1】:

这不是错误,而是有意识的更改,请参阅https://github.com/spring-projects/spring-boot/issues/5307

您不应该依赖 devtools 以这种方式配置您的测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 2014-12-11
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 2020-09-07
    相关资源
    最近更新 更多