今天在启动时遇到此问题,在此记录一下解决方法.
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();
}
参考自:https://blog.csdn.net/danielinbiti/article/details/78690638