java - Spring Boot 集成测试错误:“无法解析占位符 'wiremock.server.port'”在不需要 Wiremock 的测试中
问题描述
我有一个测试 a及其方法@SpringBootTest
的加载。@ConfigurationProperties
它在test
源集中。
而且,在 中itest
,我有一个使用 Wiremock 的集成测试(发送请求并使用存根作为响应等)
现在,当我运行时gradle test
,第一个测试失败,说:
[ENV=local] [productName=app-gateway-api] [2019-10-22T16:18:30.994Z] [ERROR] [MSG=[Test worker] osboot.SpringApplication - 应用程序运行失败 org.springframework.beans.factory .UnsatisfiedDependencyException:创建文件 [E:\coding\code\app\build\classes\java\main\com\app\controller\MyController> .class] 中定义的名称为“myController”的 bean 时出错:通过构造函数参数表示的依赖关系不满足0; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“proxyService”的 bean 时出错:注入自动装配的依赖项失败;嵌套异常是 java.lang.IllegalArgumentException:无法解析值“ http://localhost :${wiremock.server.port}/send”中的占位符“wiremock.server.port”
用于一些外部属性。该值将在 中使用itest
,但不在 中test
。但是上下文总是加载它。
在其他像这样使用它的项目中,没有问题。但是,它似乎正在加载所有类并且找不到 Wiremock 并创建服务器。
有问题的测试:
@SpringBootTest
public class MapperLookupTest {
...
}
Wiremock 依赖已经有compile
作用域:
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}
推荐阅读
- javascript - 数组数组中的公共值 - lodash
- python - 返回嵌套列表中元素的函数
- angular - Angular PrimeNG:如何检查分页器的状态?
- html - 如何将 CSS 卡放在背景图像上
- sql - select sql 返回正确的结果,但基于相同的 select 语句插入返回 NULL
- javascript - 如何删除 JavaScript 中的占位符文本?
- ios - 即使我从同一个线程调用,在内存领域中也会丢失数据
- scala - 寻找允许类产生演员的抽象
- reactjs - 我是否必须在此降级 sass 版本?
- excel - 使用动态单元格在工作簿之间复制数据