小编Sti*_*imp的帖子

如何在Spring Boot Feign Client上定义全局静态标头

我有一个Spring Boot应用程序,想要创建一个Feign客户端,该客户端具有静态定义的标头值(用于auth,但不用于基本auth)。我找到了@Headers注释,但它似乎在Spring Boot领域中不起作用。我怀疑这与使用SpringMvcContract

这是我要工作的代码:

@FeignClient(name = "foo", url = "http://localhost:4444/feign")
@Headers({"myHeader:value"})
public interface LocalhostClient {
Run Code Online (Sandbox Code Playgroud)

但是它不添加标题。

我用自己的尝试制作了一个干净的Spring Boot应用程序,并将其发布到github上:github示例

我能够使其起作用的唯一方法是将其定义RequestInterceptor为全局bean,但是我不想这样做,因为它会影响其他客户端。

spring-boot feign

2
推荐指数
2
解决办法
2589
查看次数

标签 统计

feign ×1

spring-boot ×1