feign三:覆写feign的默认配置及feign的日志
feign三:覆写feign的默认配置及feign的日志
默认配置复写
本项目地址:http://192.168.1.103:7601
本例是通过feign调用 eureka项目中的/eureka/apps/,获取相关项目的说明信息
http://localhost:8761/eureka/apps
1.首先需要在入口app处添加feign注解:@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
@EnableFeignClients
public class FeignApp { public static void main(String[] args) {
SpringApplication.run(FeignApp.class, args);
}
}
2.创建feign复写的配置:FooConfiguration2
@Configuration
public class FooConfiguration2 { /**
* 配置Url用户和密码,当eureka启用用户名和密码时
* @return
*/
/*@Bean
public BasicAuthRequestInterceptor basicAuthRequestInterceptor()
{
return new BasicAuthRequestInterceptor("root", "root123"); }*/ //默认配置
@Bean
public Contract getContract()
{
return new feign.Contract.Default(); } }
3.创建调用的client: UserFeignClient2
注意:@FeignClient 配置说明
当@FeignClient有name和url还有configuration时,取值为url的地址,name只是为一个名称而已(无意义)
当@FeignClient只有name和configuration时,name的取值为eureka中的application项目的名称即虚拟地址
/**
* 当@FeignClient有name和url还有configuration时,取值为url的地址,name只是为一个名称而已(无意义)
* 当@FeignClient只有name和configuration时,name的取值为eureka中的application项目的名称即虚拟地址
* @author Administrator
*
*/
@FeignClient(name="boot-user", url="http://localhost:8761", configuration=FooConfiguration2.class)
public interface UserFeignClient2 { @RequestLine("GET /eureka/apps/{serviceName}")
public String findServiceInfoFromEurekaByServiceName(@Param("serviceName") String serviceName); //@RequestLine("GET /simple/{id}")
//public User findById(@Param("id") Long id);
}
5.controller调用client
@RestController
public class UserController { @Autowired
private UserFeignClient userFeignClient; @Autowired
private UserFeignClient2 userFeignClient2; @GetMapping("/simple/{id}")
public User findById(@PathVariable Long id) {
return this.userFeignClient.findById(id);
} //@GetMapping("/sip/{id}")
//public User findByIdSip(@PathVariable Long id)
//{
// return this.userFeignClient2.findById(id);
//} @GetMapping("/eureka/apps/{serviceName}")
public String findEurekaInfo(@PathVariable String serviceName) {
return this.userFeignClient2.findServiceInfoFromEurekaByServiceName(serviceName);
} }
调用:
http://192.168.1.103:7601/eureka/apps/SPRING-BOOT-USER
Feign日志添加:
1.在配置文件applicaton.propreties文件中添加配置
#loging.level.+Feign客户端路径
logging.level.com.muyang.bootmovie.feign.UserFeignClient2=debug
注意上面的内容:loggin的配置:
loging.level.+Feign客户端路径
com.muyang.bootmovie.feign.UserFeignClient2 ,client是我controller需要调用的 2.在复写的configureration加入logger的bean注解
//feign日志配置
@Bean
Logger.Level feignLoggerLevel()
{
return Logger.Level.FULL;
}
3.在实际访问:http://192.168.1.103:7601/eureka/apps/SPRING-BOOT-USER时
在访问http://192.168.1.103:7601/eureka/apps/SPRING-BOOT-USER时得出的xml/string信息会以日志的形式输出
feign三:覆写feign的默认配置及feign的日志的更多相关文章
- spring cloud feign覆写默认配置级feign client的日志打印
一.覆写fegin的默认配置 1.新增配置类FeignConfiguration.java package com.config; import org.springframework.context ...
- 日志审计与分析实验三(rsyslog服务器端和客户端配置)(Linux日志收集)
Linux日志收集 一.实验目的: 1.掌握rsyslog配置方法 2.配置rsyslog服务收集其他Linux服务器日志: C/S架构:客户端将其日志上传到服务器端,通过对服务器端日志的查询,来实现 ...
- Java 覆写初探
Java 覆写 继承性的主要特征是子类可以根据父类已有的功能进行功能扩展,但是在子类定义属性或方法的时候有可能定义属性和方法和父类同名,在此类情况下就称为:“覆写”. 方法的覆写:[改良原本功能不足的 ...
- Feign二:复写Feign的默认配置
Feign二:复写Feign的默认配置 1.在启动文件加入feign注解:@EnableFeignClients FeignApp.java import org.springframework.bo ...
- java架构之路-(微服务专题)feign的基本使用和nacos的配置中心
上次回归: 上次我们说了ribbon的基本使用,包括里面的内部算法,算法的细粒度配置,还有我们自己如何实现我们自己的算法,主要还是一些基本使用的知识,还不会使用ribbon的小伙伴可以回去看一下上一篇 ...
- Struts2第三篇【Action开发方式、通配符、Struts常量、跳转全局视图、action节点默认配置】
前言 上篇Struts博文已经讲解了Struts的开发步骤以及执行流程了-..对Struts的配置文件有了了解-..本博文继续讲解Struts在配置的时候一些值得要学习的细节- Action开发的三种 ...
- Feign 失败降级未生效和超时配置优先级问题
一.问题: 生产环境服务A 通过feign调用 服务B,服务A报警信息如下: 详细分析发现问题 (1)服务A调用服务B失败,未触发声明的失败降级操作 (2)同时配置ribbon和feign超时时间,优 ...
- Spring Cloud Feign 在调用接口类上,配置熔断 fallback后,输出异常
Spring Cloud Feign 在调用接口类上,配置熔断 fallback后,出现请求异常时,会进入熔断处理,但是不会抛出异常信息. 经过以下配置,可以抛出异常: 将原有ErrorEncoder ...
- (三)Spring Boot 官网文档学习之默认配置
文章目录 继承 `spring-boot-starter-parent` 覆盖默认配置 启动器 原文地址:https://docs.spring.io/spring-boot/docs/2.1.3.R ...
随机推荐
- Codeforces 832E Vasya and Shifts - 高斯消元
题目传送门 快速的传送门I 快速的传送门II 题目大意 (题意比较复杂,请自行阅读原题) 可以将原题的字母都看成它们的在字符表中的下标,这样问题就变成给定$n$个$m$维向量$\vec{a_{1}}, ...
- centos7 install fastdfs nginx
https://github.com/judasn/Linux-Tutorial/blob/master/markdown-file/FastDFS-Nginx-Lua-GraphicsMagick. ...
- wait()和notify()的理解与使用
void notify() Wakes up a single thread that is waiting on this object’s monitor. 译:唤醒在此对象监视器上等待的单个线程 ...
- 碎碎念android eMMC【转】
本文转载自:https://blog.csdn.net/Fybon/article/details/44242549 一./dev/blockroot@:/dev/block #ls bootdevi ...
- Yii使用笔记 2
yii中的 getId等函数, id更多的是一个 string, 而不是数字. CCaptchaAction > CAction > CComponent. 实现是 IAction. yi ...
- How to resize slide dimensions without resizing any objects on the slide?
IF you are competent to unzip the pptx file and modify the XML it can be done, the slide size will c ...
- String comparison is too slow in R language
## String comparison is too slow in R language ## it will take 3 minutes, it is too slow date() strA ...
- WinMerge 过滤器用法
WinMerge是一款开源的文件对比合并工具.http://winmerge.org/WinMerge提供了“过滤器”功能,可以在对比时排除特定的目录或文件. 1.编辑过滤规则工具 -> 过滤器 ...
- 非托管C++互操作
.NET简谈互操作(一:开篇介绍) .NET简谈互操作(二:先睹为快) .NET简谈互操作(三:基础知识之DllImport特性) .NET简谈互操作(四:基础知识之Dispose非托管内存) .NE ...
- 浅谈 Make 命令
代码变成可执行文件,叫做编译(compile):先编译这个,还是先编译那个(即编译的安排),叫做构建(build). Make是最常用的构建工具,诞生于1977年,主要用于C语言的项目.但是实际上 , ...