介绍
使用
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
注:可以精确到某一个模块,甚至是模块下的文件夹