OKhttp3

 针对上一博文订单调用用户使用默认数据交互方式,下面介绍下使用 Okhttp3网络数据交换方式。

1、订单启动类变化

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());
	}
}

 2、在pox.xml文件中引用okhttp3 引用包

 

访问方式不变:既:

原文地址:https://www.cnblogs.com/northeastTycoon/p/10463906.html