【SpringBoot】RestTemplate呼叫報錯:'org.springframework.web.client.RestTemplate' that could not be found.
@Autowired
public RestTemplate restTemplate;
時報錯,錯誤資訊如下
錯誤:'org.springframework.web.client.RestTemplate' that could not be found.
改為:
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
String providerMsg = restTemplate().getForEntity("http://localhost:8009/ecif-business/PrpObject/test",String.class).getBody();
System.out.println("Hello,Customer! msg from provider : <br/><br/> " + providerMsg);;
後即正確
此種方式為Spring Boot<=1.3時使用的,在>=1.4版本後,可以通過RestTemplateBuilder來使用。