SpringBoot 2.2.5 cannot automatically inject RestTemplate

  • Stray information
Consider defining a bean of type 'org.springframework.web.client.RestTemplate' 
in your configuration.
No qualifying bean of type [org.springframework.web.client.RestTemplate] found
  • the reason
Spring Boot<=1.3 无需定义,Spring Boot自动为您定义了一个。
 
Spring Boot >= 1.4 Spring Boot不再自动定义一个RestTemplate,
  而是定义了一个RestTemplateBuilder允许您更好地控制所RestTemplate创建的对象
  • solution

    Define RestTemplate Bean to complete the injection

@Configuration
public class RestTemplateConfig {

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

 

Guess you like

Origin blog.csdn.net/qq_41893274/article/details/105064993