針對上一博文訂單調用用戶使用默認數據交互方式,下面介紹下使用 Okhttp3網絡數據交換方式。java
一、訂單啓動類變化web
package com.tycoon.orderService; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.http.client.OkHttp3ClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; /** * Class Name: OrderApplication.java * Description: Order啓動類 * @author northeasttycoon DateTime 2019年3月1日 上午6:53:49 * @company tycoon * @version 1.0 */ @SpringBootApplication public class OrderApplication { public static void main(String[] args) { SpringApplication.run(OrderApplication.class, args); } // http://localhost:9091/order/findById/1 // 第一種:使用默認傳輸方式 // @Bean // public RestTemplate restTemplate(){ // return new RestTemplate(); // } // 第二種使用 okhttp3 @Bean public RestTemplate restTemplate(){ return new RestTemplate(new OkHttp3ClientHttpRequestFactory()); } }
二、在pox.xml文件中引用okhttp3 引用包spring
訪問方式不變:既:網絡