Spring Boot <= 1.3

No need to define one, Spring Boot automatically defines one for you.
(springboot1.3版本以前不需要自定义一个RestTemplate,springboot为你自动定义了一个)

Spring Boot >= 1.4

Spring Boot no longer automatically defines a RestTemplate but instead defines a RestTemplateBuilder allowing you more control over the RestTemplate that gets created. You can inject the RestTemplateBuilder as an argument in your @Bean method to create a RestTemplate:
(springboot1.4版本以后需要在启动器里自定义RestTemplate,即在启动器中加入如下代码即可在类中正常使用@Autowired进行注入)

 @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder){
        return builder.build();
    }

 参考自:RestTemplate注入_danielinbiti的博客-CSDN博客_resttemplate注入

更多推荐

服务启动报错:Consider defining a bean of type ‘.RestTemplate‘ in your configuration