spring boot 通过feign调用api接口
目的:远程调用服务器api,直接上步骤:
1,添加maven依赖,这是必须的:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> </dependency>
<dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-core</artifactId> <version>9.5.0</version> </dependency> <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-slf4j</artifactId> <version>9.5.0</version> </dependency> <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-hystrix</artifactId> <version>9.5.0</version> </dependency> <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-jackson</artifactId> <version>9.5.0</version> </dependency
2,接口远程请求:这个接口请求远程api,然后本地service层调用接口方法就好了
3,需要添加配置:
yml配置:
4:调用这个接口就好了:构造器注入,然后直接调用即可
private final QrCodeFeignClient qrCodeFeignClient; public QrCodeServiceImpl(QrCodeFeignClient qrCodeFeignClient) { this.qrCodeFeignClient = qrCodeFeignClient; } qrCodeFeignClient.timingGetData("", "", "", new String[1], 1);