FeignClient的使用及调用日志打印到控制台

介绍

FeignClient_java_我好帅啊~-DevPress官方社区

使用

1、在yml中配置依赖项

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-openfeign-core</artifactId>
            <version>3.1.5</version>
        </dependency>

2、定义接口

@FeignClient(name = "config", url = "${xxx.xxx}")
public interface GetBonusPointsConfigClient {
    /*
     * 查询个人或者企业积分兑换比率
     * @param reqDto
     * @param memberId 会员id
     * @return 
     */
    @PostMapping(value = "/config/queryConfig")
    RestResponse<xxxx> GetExchangeRate(@RequestBody xxx reqDto, @RequestHeader("memberId") String memberId);
}

3、在启动类上打 @EnableFeignClients注解

@SpringBootApplication
@ComponentScan(basePackages = "com.xxx.*")                 //开启扫描组件
@MapperScan(basePackages = "com.xxx.xxx.data.mapper")     //数据库表对应的映射文件扫描
@EnableFeignClients(basePackages = "com.xxx.*")            //开启对 Feign Client 扫描加载
@EnableAsync
@EnableSwagger2
@EnableTransactionManagement
public class MallApplication {
    public static void main(String[] args) {
        SpringApplication.run(MallApplication.class, args);
    }
}

如何将日志打印到控制台

在yml中做如下两个配置:

1、

(1)第一种可以在yml中配置

feign:
  client:
    config:
      default:
        logger-level: FULL

(2)、也可以硬编码,开发一个组件类

@Configuration
public class FeignConfiguration {
    @Bean
    Logger.Level feignLoggerLevel(){
        //这里记录所有级别的日志。根据实际情况选择合适的日志level
        return Logger.Level.FULL;
    }
}

2、在yml中配置日志级别为debug 

logging:
  level:
    com.xxx.xxx.*: debug

   注:可以精确到某一个模块,甚至是模块下的文件夹                      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值