• spring feign依赖包


    1.feign依赖包

    <properties>
            <java.version>1.8</java.version>
            <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
        </properties>
      <!-- 管理springboot相关依赖的版本例如:web,jdbc,test -->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.4.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
    
        <dependencies>
         <!-- feign客户端依赖 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-openfeign</artifactId>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.16.10</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <scope>test</scope>
            </dependency>
         <!-- feign使用服务id获取加请求路径获取的负载均衡依赖 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>com.github.jsonzou</groupId>
                <artifactId>jmockdata</artifactId>
                <version>4.1.1</version>
                <scope>test</scope>
            </dependency>
    
        </dependencies>
    <!-- 管理spring cloud依赖的版本,例如,feign,负载均衡的ribbon
    -->
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring-cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    <!-- eureka-client 包括了eureka客户端所有的依赖。
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
     -->
     

     2.Java类注释写法

    @SpringBootApplication
    @EnableDiscoveryClient
    @RestController
    @EnableFeignClients
    public class DemoApplication {
        @Autowired
        HelloClient client;
    
        @RequestMapping("/")
        public String hello() {
            return client.hello();
        }
    
        public static void main(String[] args) {
            SpringApplication.run(DemoApplication.class, args);
        }
    
        @FeignClient("HelloServer")
        interface HelloClient {
            @RequestMapping(value = "/", method = GET)
            String hello();
        }
    }

    3.yml配置

    debug: true
    
    spring:
      application:
        name: nuts-warehouse-feign
    
    server:
      port: 8085
    
    eureka:
      client:
        serviceUrl:
          defaultZone: http://10.202.200.147:8081/eureka
  • 相关阅读:
    Viewer.js 图片预览插件使用
    SqlServer关于“无法删除数据库 "XXXX",因为该数据库当前正在使用”问题的解决方案
    MySQL数据类型详解
    Node.js安装详细步骤教程(Windows版)
    RGB颜色查询对照表
    HTML加载FLASH(*.swf文件)详解
    Cesium区分单击【LEFT_CLICK】和双击事件【LEFT_DOUBLE_CLICK】
    SpringBoot访问jsp页面
    Servlet详解
    Session的生命同期
  • 原文地址:https://www.cnblogs.com/z-test/p/10815384.html
Copyright © 2020-2023  润新知