Skip to content

服务器托管,北京服务器托管,服务器租用-价格及机房咨询

Menu
  • 首页
  • 关于我们
  • 新闻资讯
  • 数据中心
  • 服务器托管
  • 服务器租用
  • 机房租用
  • 支持中心
  • 解决方案
  • 联系我们
Menu

SpringBoot3.0: HttpExchange来调用Http接口

Posted on 2023年5月6日 by hackdl

一、依赖



    4.0.0

    com.ub
    data-importer2023
    1.0.0


    
        17
        17
            UTF-8
            1.54.0
    

    
        org.springframework.boot
        spring-boot-starter-parent
        3.0.5
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-webflux
        


    

    
        
            
                kr.motd.maven
                os-maven-plugin
                1.7.1
            
        
        
            
                org.xolstice.maven.plugins
                protobuf-maven-plugin
                0.6.1
                
                    com.google.protobuf:protoc:3.21.7:exe:${os.detected.classifier}
                    grpc-java
                    io.grpc:protoc-gen-grpc-java:1.54.0:exe:${os.detected.classifier}
                
                
                    
                        
                            compile
                            compile-custom
                        
                    
                
            
        
    


二、定义一个http接口

package com.ub.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {
    @RequestMapping("/hi")
    public String hi(@RequestParam("username") String username,
                     @RequestParam("password")String password){
        return username+","+password;
    }
}

三、定义声明式HttpExchange接口

package com.ub.service;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.service.annotation.GetExchange;
import org.springframework.web.service.annotation.HttpExchange;

@HttpExchange
public interface HttpService {

    @GetExchange("hi")
    String login(@RequestParam("username") String username, @RequestParam("password") String password);
}

四、使用HttpExchange接口调用http服务

package com.ub.controller;

import com.ub.service.HttpService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

@RestController
public class HttpController {
    @RequestMapping("/test")
    public String test(){
        WebClient client = WebClient.builder().baseUrl("http://localhost:8088/").build();
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();
        HttpService httpService = factory.createClient(HttpService.class);
        return httpService.login("tju","fgh");
    }
}

服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net

Related posts:

  1. 机柜租用合同新版
  2. 福建IP服务器托管服务器:安全高效的网络托管服务
  3. K3S 系列文章-5G IoT 网关设备 POD 访问报错 DNS ‘i/o timeout’分析与解决
  4. 深入了解服务器托管与私有云的优缺点
  5. 哈尔滨联通服务器托管服务:高效安全稳定

服务器托管,北京服务器托管,服务器租用,机房机柜带宽租用

服务器托管

咨询:董先生

电话13051898268 QQ/微信93663045!

上一篇: jvm复习:几个参数的设置
下一篇: MySQL 数据库运维与管理相关命令

最新更新

  • 五月学习之keepalived 软件简介
  • Cibersort免疫浸润的在线分析及R语言代码实现
  • 阿里云的认证最有几个等级?考试费用是多少?
  • 京东APP百亿级商品与车关系数据检索实践 | 京东云技术团队
  • 【Hello Network】TCP协议 TCP协议 确认应答机制 (ACK) 超时重传机制 连接管理机制 流量控制 滑动窗口 拥塞控制 延时应答 捎带应答 面向字节流 粘包问题 TCP的异常情况 TCP小结 基于TCP的应用层协议

随机推荐

  • oracle执行cmd的实现方法
  • Python模拟星空 前言 Turtle基础 模拟
  • 乐昌服务器租赁托管厂家批发价格指南
  • 实现高效稳定的托管前端服务器方案
  • 5G承载网里的FlexE,到底是什么?

客服咨询

  • 董先生
  • 微信/QQ:93663045
  • 电话:13051898268
  • 邮箱:dongli@hhisp.com
  • 地址:北京市石景山区重聚园甲18号2层

友情链接

  • 服务器托管
  • 服务器租用
  • 机房租用托管
  • 服务器租用托管
©2023 服务器托管,北京服务器托管,服务器租用-价格及机房咨询 京ICP备13047091号-8