Springboot启动报错
Consider defining a bean of type ‘org.springframework.web.client.RestTemplate’ in your configuration.
原因 :
注入 RestTemplate 后,提示 Could not autowire. No beans of ‘RestTemplate’ type found.
不能自动装配,没有找到 RestTemplate 的bean
解决办法:
springboot 1.4版本之后,需要在启动类注入 RestTemplate
添加代码
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
再次启动项目,就可以成功了!