我有一个@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:无法解析占位符价值'wiremock.server.port'“ http://localhost:$ {wiremock.server.port} / send”
在某些外部属性中使用。
在其他使用它的项目中,没有问题。但是,似乎它正在加载所有类并且无法找到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}