Field restTemplate in com.jack.springcloud.controller.DeptController_Consumer required a bean of typ

出现问题:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field restTemplate in com.jack.springcloud.controller.DeptController_Consumer required a bean of type 'org.springframework.web.client.RestTemplate' that could not be found.


Action:

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

 

解决方案:

在启动类添加如下代码:

	@Bean
	public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
		return new RestTemplate(factory);
	}

	@Bean
	public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
		SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
		factory.setReadTimeout(180000);//单位为ms
		factory.setConnectTimeout(5000);//单位为ms
		return factory;
	}

 

你可能感兴趣的:(springcloud)