Description:
Field restTemplate in com.imooc.controller.OrdersController required a bean of type 'org.springframework.web.client.RestTemplate' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.
解决办法:在启动类中添加:
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder){
return builder.build();
}

这样,即可解决
这篇博客主要讨论了在Spring Boot应用中遇到的RestTemplate注入失败的错误。问题表现为缺少RestTemplate类型的bean。解决方案是在启动类中添加@Bean注解,创建RestTemplate实例。通过这种方式,可以成功配置并解决依赖注入的问题。
1430

被折叠的 条评论
为什么被折叠?



