【发布时间】:2017-05-31 02:44:21
【问题描述】:
我在测试 Spring 控制器时遇到了问题。 我在我的测试类中使用注释@WebMvcTest。 当我运行测试时,我得到这个错误: 没有可用的“org.springframework.boot.web.client.RestTemplateBuilder”类型的合格 bean
我将 RestTemplate 用于项目中的其他类,因此我在主类中定义了一个 bean:
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
为了让它工作,我必须这样定义我的 restTemplate bean:
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
是 @WebMvcTest 注释有问题还是我遗漏了什么?
谢谢
【问题讨论】:
-
刚刚跳进了同一个问题,对我来说它看起来像一个错误,找不到太多的东西。有更新吗?
标签: java spring spring-boot junit resttemplate