分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

OKhttp3

发布时间:2023-09-06 02:34责任编辑:彭小芳关键词:http

 针对上一博文订单调用用户使用默认数据交互方式,下面介绍下使用 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 */@SpringBootApplicationpublic 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@Beanpublic RestTemplate restTemplate(){return new RestTemplate(new OkHttp3ClientHttpRequestFactory());}}

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

 

访问方式不变:既:

OKhttp3

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved