gpt4 book ai didi

java - Spring Boot集成测试错误: "Could not resolve placeholder ' wiremock. server.port'”在不需要Wiremock的测试中

转载 作者:行者123 更新时间:2023-12-02 09:23:29 29 4
gpt4 key购买 nike

我有一个@SpringBootTest,它测试@ConfigurationProperties及其方法的加载。它位于 test 源集中。

并且,在 itest 中,我有一个使用 Wiremock 的集成测试(发送请求并使用 stub 作为响应等)

现在,当我运行 gradle test 时,第一个测试失败,并显示:

[ENV=local] [productName=app-gateway-api] [2019-10-22T16:18:30.994Z] [ERROR] [MSG=[Test worker] o.s.boot.SpringApplication - Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myController' defined in file [E:\coding\code\app\build\classes\java\main\com\app\controller\MyController> .class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'proxyService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'wiremock.server.port' in value "http://localhost:${wiremock.server.port}/send"

用于一些外部属性。该值将在 itest 中使用,但不会在 test 中使用。但上下文总是加载它。

在其他项目中这样使用是没有问题的。但是,它似乎正在加载所有类,并且无法找到 Wiremock 并创建服务器。

问题测试:

@SpringBootTest
public class MapperLookupTest {
...
}

Wiremock 依赖项已具有编译范围:

    compile('com.github.tomakehurst:wiremock-jre8-standalone:2.21.0')
compile("org.springframework.cloud:spring-cloud-starter-contract-stub-runner")

我尝试使用@SpringBootTest(classes = {...})仅加载必要的类,但它太冗长了。

那么,有没有什么简单的方法来告诉上下文加载Wiremock?

最佳答案

只需向占位符添加默认值即可:

${wiremock.server.port:defaultValue}

关于java - Spring Boot集成测试错误: "Could not resolve placeholder ' wiremock. server.port'”在不需要Wiremock的测试中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58508678/

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