添加主要依赖

使用Feign访问接口的配置,如果服务不在Eureka上,可以不加Eureka的依赖,用在FeignClient上指定url的方式访问

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter-feign')
compile('org.springframework.cloud:spring-cloud-starter-eureka')
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.12'
testCompile('org.springframework.boot:spring-boot-starter-test')
}

gradle配置文件

buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
} apply plugin: 'java'
apply plugin: 'org.springframework.boot' group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8 repositories {
mavenCentral()
} dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter-feign')
compile('org.springframework.cloud:spring-cloud-starter-eureka')
testCompile('org.springframework.boot:spring-boot-starter-test')
} ext {
springCloudVersion = 'Dalston.SR4'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

配置文件中Eureka地址

(下面是yml文件的配置格式)

eureka:
client:
enabled: true #访问eureka服务时要打开
serviceUrl:
defaultZone: http://localhost:8761/eureka/

Application主类添加注解

@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication
public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }

编写FeignClient接口

dp-dealer-shop是指定的应用名,不用Eureka的话不可以这样做,可以用指定一个Name和Url的方式调用接口
接口中不支持@GetMapping这样的简写,要用@RequestMapping的写法
@FeignClient("dp-dealer-shop")

public interface Feign {
@RequestMapping(method = RequestMethod.GET, value = "/api/quotation/v0/sendLargeRegionMail")
List<AuditEmailContentDto> getLargeRegionMailContent();
}

最新文章

  1. 全面分析 Spring 的编程式事务管理及声明式事务管理
  2. 最短路模板(Dijkstra &amp; Dijkstra算法+堆优化 &amp; bellman_ford &amp; 单源最短路SPFA)
  3. Mvc action间的传值
  4. htpasswd命令
  5. Scrum不是万能药,要在时机成熟时推行
  6. Servlet/JSP-01 Servlet及其生命周期
  7. Java 基本数据类型 sizeof 功能【转】
  8. swift和oc混编
  9. 安卓和iOS移动APP开发设计应该考虑哪些问题
  10. JDBC详解系列(四)之建立Stament和执行SQL语句
  11. nginx日志格式定义和nginx.conf配置模板说明
  12. ubuntu18.04LTS配置apache虚拟目录(基于端口)
  13. win 10 在vs2017下对mpi的安装以及认识
  14. Ubuntu下解压缩文件
  15. 关于浏览器对html, js,css的解析先后顺序的理解
  16. Qt编写高仿苹果MAC电脑输入法(支持触摸滑动选词)
  17. Linux 用户名、主机添加背景色
  18. String中根据,(逗号)进行分割
  19. JDK版本的特性
  20. Pig的安装和简单使用

热门文章

  1. 基于Rancher搭建Kubernetes
  2. Function题解
  3. 常用的webpack优化方法
  4. apache+php+mysql搭建php环境
  5. 通俗地说逻辑回归【Logistic regression】算法(二)sklearn逻辑回归实战
  6. Java 博客系统 Tale
  7. 你知道如何优化Join语句吗?
  8. day5-基本数据类型总结
  9. MyBatis --- 映射关系【一对一、一对多、多对多】,懒加载机制
  10. 深入理解计算机系统 第二章 信息的表示和处理 part2