RestTemplate无法注入

≡放荡痞女 提交于 2020-01-18 18:14:02

原因:
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();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!