使用Feign访问接口
添加主要依赖
使用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();
}
使用Feign访问接口的更多相关文章
- 没有活动事务 链接服务器的 OLE DB 访问接口 "SQLNCLI" 无法启动分布式事务
在windows2003下执行分布式事务的时候出现如下情况. 一. 问题现象在执行分布式事务时,在sql server 2005下收到如下错误: 链接服务器"xxxxxxx"的 O ...
- Dojo Data Store——统一数据访问接口
原文地址:http://www.infoq.com/cn/articles/wq-dojo-data-store 无论在传统的桌面应用还是在主流的互联网应用中,数据始终占据着软件应用中的核心地位.当下 ...
- java servlet手机app访问接口(一)数据加密传输验证
前面几篇关于servlet的随笔,算是拉通了 servlet的简单使用流程,接下去的文章将主要围绕手机APP访问接口这块出发续写,md5加密传输--->短信验证--->手机推送---> ...
- 链接服务器"(null)"的 OLE DB 访问接口 "Microsoft.Jet.OLEDB.4.0" 返回了消息 "未指定的错误"。[手稿]
消息 7302,级别 16,状态 1,第 1 行 无法创建链接服务器 "(null)" 的 OLE DB 访问接口 "Microsoft.JET.OLEDB.4.0&qu ...
- 无法创建链接服务器 "TEST" 的 OLE DB 访问接口 "OraOLEDB.Oracle" 的实例
在使用SQLserver建立远程服务连接Oracle的时候出现先下面错误 出现这个错误,我找到最常见的两个原因 1.注册表 <1>按下WIN+R,打开“运行”窗口,输入“regedit”, ...
- 21. 无法执行该操作,因为链接服务器”Server_202”的 OLE DB 访问接口 “SQLNCLI10″ 无法启动分布式事务”
无法执行该操作,因为链接服务器”Server_202”的 OLE DB 访问接口 “SQLNCLI10″ 无法启动分布式事务” 原因:调用存储过程的方式有问题,必须用JDBC方式调用存储过程才可以正常 ...
- 无法创建链接服务器 "xxx" 的 OLE DB 访问接口 "OraOLEDB.Oracle" 的实例。 (Microsoft SQL Server,错误: 7302)
出现这个错误,有两个最常见的两个原因 1.注册表 <1>按下WIN+R,打开“运行”窗口,输入“regedit”,回车 <2>在打开的注册表编辑器的左侧按如下路径依次展开: H ...
- Java学习-052-(mybatis+mysql)访问接口时提示:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
在配置mybatis,访问接口提示: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found),部 ...
- 关于:无法创建链接服务器 "ORCL" 的 OLE DB 访问接口 "OraOLEDB.Oracle" 的实例 (错误:7302)
本人接触和使用Oracle数据库才有一个季度的时间,问题比较白,大神请无视本文. 环境: 1.数据服务器,windows2008R2,Oracle11g 2.报表服务器,windows2008R2,S ...
随机推荐
- Unix/Linux 从哪儿来?那些改变世界的人们...
昨天看文章时发现自己对 linux 操作系统不够了解,还记得 17 年时听过老师的一些课,对 linux 的历史有一点了解,不过当时并没有记录笔记,现在已经忘的差不多了. 这次从网上找资料,又重新看了 ...
- 大数据之路day02_2--if switch while for
在这一节,学习程序流程控制,具体包括判断结构.选择结构.循环结构. 1.判断结构(if.if-else) 三元运算符和if-else的区别 三元运算符,是一个运算符,所以运行必须有结果 而if-els ...
- inline-block元素间隙产生及去除方法
当我们把元素属性display设置成inline-block时,元素之间就会产生间隙 <!DOCTYPE html><html> <head> <meta c ...
- php 5.5使用 array_column的方法
<pre>php 5.5使用 array_column的方法</pre> <pre> public function array_column($input, $c ...
- Java把一个文件,输出成多个文件
前言:我有一个出租车轨迹的txt文本,其中包括多条轨迹.我想把这个文本按照单条轨迹输出出来,每条轨迹放在一个txt文本中. 思路:重要问题就集中在,如何动态的指定输出文件的名字.我想到了StringB ...
- Linux系统中nc工具那些不为人知的用法
Linux nc命令用法 参考地址:https://www.cnblogs.com/jjzd/p/6306273.html -g<网关>:设置路由器跃程通信网关,最多设置8个; -G< ...
- [WPF] Caliburn Micro学习二 Infrastructure
Caliburn Micro学习一 Installation http://blog.csdn.net/alvachien/article/details/12985415 Step 1. 无论是通过 ...
- nyoj 26-孪生素数问题(打表)
26-孪生素数问题 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:10 submit:43 题目描述: 写一个程序,找出给出素数范围内的所有孪生素数 ...
- Go 语言优秀资源整理,为项目落地加速🏃
最后更新于2019.11.22 Go 语言优秀资源整理,为项目落地加速
- python:调用bash
利用os模块 python调用Shell脚本,有三种方法: os.system(cmd)返回值是脚本的退出状态码 os.popen(cmd)返回值是脚本执行过程中的输出内容 commands.gets ...