openFeign的使用


作用

  類似ribbon提供客戶端的負載均衡

1:pom

 

 <!---  eureka-client  -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <!-- openfeign  -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

 

2:yml

 

server:
  port: 80 #服務端口號

spring:
  application:
    name: cloud-order-service

eureka:
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7001.com:7001/eureka/

 

3:seivice接口

 

@Component
@FeignClient(value = "CLOUD-PAYMENT-SERVICE")
public interface PaymentService {

    @GetMapping(value = "/payment/get/{id}")
    BaseResult findById(@PathVariable("id") Integer id);
} 
  @FeignClient  //#標記該類為openFeign的接口
  (value = "CLOUD-PAYMENT-SERVICE")  //#eureka服務的提供方

 

4:啟動類

 

@SpringBootApplication
@EnableFeignClients
public class FeignOrderMain80 {

    public static void main(String[] args) {
        SpringApplication.run(FeignOrderMain80.class);
    }
}

 

  @EnableFeignClients  #開啟使用openFeign

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM