一、覆写fegin的默认配置

1、新增配置类FeignConfiguration.java

package com.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import feign.Contract;
import feign.Logger;
@Configuration
public class FeignConfiguration { @Bean
public Contract feignContract() {
//这里可以配置默认配置
return new feign.Contract.Default();
} @Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}

需要之一的是此配置文件不能再spring cloud扫描包的路径下,否则会有问题出现

2、定义一个FeignClient2.java

package com.pupeiyuan.feignClient;

import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import com.config.FeignConfiguration;
import com.pupeiyuan.bean.NhReportStatusHistory; import feign.Param;
import feign.RequestLine; @FeignClient(name = "MULTIPLE",configuration = FeignConfiguration.class)
public interface FeignClient2 {

  

@RequestLine("GET /getDate/{id}")
  public List<NhReportStatusHistory> dataList(@Param("id") Long id);

}

3、controller中调用

FeignClientController.java

package com.pupeiyuan.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.pupeiyuan.bean.NhReportStatusHistory;
import com.pupeiyuan.feignClient.FeignClient2;
import com.pupeiyuan.feignClient.UserFeignClient; @RestController
public class FeignClientController { @Autowired
private FeignClient2 feignClient2; @GetMapping("/movie2/{id}")
public List<NhReportStatusHistory> list2(@PathVariable Long id) {
return this.feignClient2.dataList(id);
}
}

实现的效果和上一篇文章是一样的

二、feign client的日志打印

默认情况下feign是没有日志打印出来的,需要增加相关配置:
1、创建Feign的配置文件,并在其中设置日志等级

/**
* Feign 客户端配置
*
* @author xushiling
* @date 2018/8/13
*/
@Configuration
public class FeignConfiguration {
@Bean
Logger.Level feignLoggerLevel() {
//这里记录所有,根据实际情况选择合适的日志level
return Logger.Level.FULL;
}
}

这里的level级别控制如下

NONE, No logging (DEFAULT).
BASIC, Log only the request method and URL and the response status code and execution time.
HEADERS, Log the basic information along with request and response headers.
FULL, Log the headers, body, and metadata for both requests and responses.
NONE, 不记录 (DEFAULT).
BASIC, 仅记录请求方式和URL及响应的状态代码与执行时间.
HEADERS, 日志的基本信息与请求及响应的头.
FULL, 记录请求与响应的头和正文及元数据.

2、在客户端接口指定此配置

package com.pupeiyuan.feignClient;

import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import com.config.FeignConfiguration;
import com.pupeiyuan.bean.NhReportStatusHistory; import feign.Param;
import feign.RequestLine; @FeignClient(name = "MULTIPLE",configuration = FeignConfiguration.class)
public interface FeignClient2 {

@RequestLine("GET /getDate/{id}")
  public List<NhReportStatusHistory> dataList(@Param("id") Long id);

}

3、配置文件开启日志记录
application.properties设置:
logging.level.com.haoait.client.UserServiceClient:debug
如果是yml配置文件则做如下配置:

logging:
level:
com.haoait.client.UserServiceClient:debug

日志输出如下:

spring cloud feign覆写默认配置级feign client的日志打印的更多相关文章

  1. feign三:覆写feign的默认配置及feign的日志

    feign三:覆写feign的默认配置及feign的日志 默认配置复写 本项目地址:http://192.168.1.103:7601 本例是通过feign调用 eureka项目中的/eureka/a ...

  2. Spring Cloud第十一篇 | 分布式配置中心高可用

    ​ 本文是Spring Cloud专栏的第十一篇文章,了解前十篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Cl ...

  3. Spring Cloud(七):配置中心(Git 版与动态刷新)【Finchley 版】

    Spring Cloud(七):配置中心(Git 版与动态刷新)[Finchley 版]  发表于 2018-04-19 |  更新于 2018-04-24 |  Spring Cloud Confi ...

  4. SpringCloud学习笔记(10)----Spring Cloud Netflix之声明式 REST客户端 -Feign的高级特性

    1. Feign的默认配置 Feign 的默认配置 Spring Cloud Netflix 提供的默认实现类:FeignClientsConfiguration 解码器:Decoder feignD ...

  5. Spring Cloud Alibaba(二) 配置中心多项目、多配置文件、分目录实现

    介绍 之前Spring Cloud Config基础篇这篇文章介绍了Spring Cloud Config 配置中心基础的实现,今天继续聊下Spring Cloud Config 并结合nacos做服 ...

  6. Spring Cloud中五大神兽总结(Eureka/Ribbon/Feign/Hystrix/zuul)

    Spring Cloud中五大神兽总结(Eureka/Ribbon/Feign/Hystrix/zuul) 1.Eureka Eureka是Netflix的一个子模块,也是核心模块之一.Eureka是 ...

  7. Spring Cloud config之一:分布式配置中心入门介绍

    Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持.配置服务器为各应用的所有环境提供了一个中心化的外部配置.它实现了对服务端和客户端对Spring Environm ...

  8. Spring Cloud(九):配置中心(消息总线)【Finchley 版】

    Spring Cloud(九):配置中心(消息总线)[Finchley 版]  发表于 2018-04-19 |  更新于 2018-05-07 |  我们在 Spring Cloud(七):配置中心 ...

  9. 【SpringCloud构建微服务系列】使用Spring Cloud Config统一管理服务配置

    一.为什么要统一管理微服务配置 对于传统的单体应用而言,常使用配置文件来管理所有配置,比如SpringBoot的application.yml文件,但是在微服务架构中全部手动修改的话很麻烦而且不易维护 ...

随机推荐

  1. java在进程启动和关闭.exe程序

    /** * @desc 启动进程 * @author zp * @date 2018-3-29 */ public static void startProc(String processName) ...

  2. nginx 模块配置

    第一个 当前活跃的连接数 nginx握手的数 连接数 总的请求数

  3. ActiveMQ中Broker的应用与启动方式

    Broker:英语有代理的意思,在activemq中,Broker就相当于一个Activemq实例. 1. 命令行启动实例: 1.activemq start使用默认的activemq.xml启动 E ...

  4. Linux下tar压缩解压缩命令详解

    tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...

  5. 记录 一次深夜救火:datanode.data.dir

    火灾背景: Hadoop集群,4个节点,每一台配置都不一样 火灾现场: 1.突然发现DN4硬盘报警,检查硬盘,发现挂载如下: /home 200GB /home/data 3TB 然后发现datano ...

  6. 全面接触PDF:最好用的PDF软件汇总(转)

    全面接触PDF:最好用的PDF软件汇总(2010-12-07更新): http://xbeta.info/pdf-software.htm 比较全面的c#帮助类,各种功能性代码: https://gi ...

  7. Windows PowerShell 入門(9)-エラー編

    対象読者 Windows PowerShellでコマンドレット操作ができる方 何らかのプログラミング経験があればなお良い 必要環境 Windows PowerShell エラーをリダイレクトする リダ ...

  8. 【转】C++ 11 并发指南一(C++ 11 多线程初探)

    引言 C++ 11自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些C++ 11的新特性,算是记录一下自己学到的东西吧,和大家共勉. 相信Linux程序员都用过Pthrea ...

  9. AngularJs 刷新页面

    第一种: AngularJs 刷新页面可采用下面的方式:首先先在控制器中注册$window,然后定义函数$scope.reloadRoute,在需要刷新页面的地方调用函数$scope.reloadRo ...

  10. mysql 5.6 windows 启动脚本

    2018-4-25 17:02:08 星期三 下载mysql 5.6 zip(免安装版)到本机 一台电脑上可能装有多个版本的mysql, 启动时为了不影响: 1. 解压后文件夹根目录改名为 mysql ...