zoukankan      html  css  js  c++  java
  • springcloud-服务之间的调用

    openFegin(声明式服务调用组件)主要是用于服务之间的调用:

    所需要的依赖:

     <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-openfeign</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    
    

    无参数的情况下:

    
    @FeignClient("provider")
    @Service
    public interface HelloService {
    
        @GetMapping("/provider/hello")
        String hello();
    
    
    
    }
    
    

    有参数的情况:

    1.有参数的情况要绑定参数

    2.如果要通过header来传参数一定要中文转码

       @GetMapping("/hello2")
        String hello2(@RequestParam("name") String name);
        
    
    //方法的提供方
    
        @RequestMapping(value = "/hello", method = RequestMethod.GET)
        public String hello(){
            return "hello SpringCloud";
        }
    
        @GetMapping("/hello2")
        public String hello2(String name){
            return "hello" + name;
        }
    

    以上我们基本就实现了服务之间的调用了

  • 相关阅读:
    Springboot集成Junit
    springboot集成mybatis
    使用Spring Initializr快速创建Springboot工程
    Tungsten Replicator学习总结
    Java代理模式汇总
    Java定时任务的常用实现
    Java对象序列化剖析
    最适合作为Java基础面试题之Singleton模式
    MyCat源码分析系列之——结果合并
    MyCat源码分析系列之——SQL下发
  • 原文地址:https://www.cnblogs.com/yjfb/p/12751821.html
Copyright © 2011-2022 走看看