原因:
RestTemplate依赖ClientHttpRequestFactory对象,无法直接注入。
报错日志:
Description:
Field rt in com.xxx.xxx.controller.xxxxxController required a bean of type ‘org.springframework.web.client.RestTemplate’ that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type ‘org.springframework.web.client.RestTemplate’ in your configuration.
解决方法:
在springBoot启动类增加RestTemplate的bean。如下:
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
@Bean
public RestTemplate restTemplate()
{
return new RestTemplate();
}