✅ 操作成功!

Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your con

发布时间:2023-06-12 作者:admin 来源:文学

Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your con

Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your con

今天在启动时遇到此问题,在此记录一下解决方法. 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(); }

参考自:blog.csdn/danielinbiti/article/details/78690638

👁️ 阅读量:0