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

编程知识 更新时间:2023-05-02 05:20:57

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

本文发布于:2023-04-26 05:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/9f12dd7b73f0702fbf892942c44b0b3e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   defining   bean   configuration   RestTemplate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104293文章数
  • 26210阅读数
  • 0评论数