【SpringBoot】RestTemplate调用报错:'org.springframework.web.client.RestTemplate' that could not be found.

来源:互联网 发布:22周排畸b超数据看男女 编辑:程序博客网 时间:2024/05/21 06:58
    RestTemplate引入方式为:
@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来使用。
阅读全文
0 0
原创粉丝点击