最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how to restrict FeignClientConfiguration to one feign client, not all? - Stack Overflow

programmeradmin4浏览0评论

We have a specific config in FeignClientConfiguration.java:

@Configuration
public class FeignClientConfiguration {
    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new BasicAuthRequestInterceptor(username, password);
    }
}

Then in one feign client in one package we have the following so that it will use the above configuration:

@FeignClient(name = "my-client", url = "https://myurl/", configuration = FeignClientConfiguration.class)
public interface MyFeignClient {

    @RequestMapping(...
}

In a separate feign client, which has a completely different purpose and endpoint, we have:

@FeignClient(name = "some-other-client", url = "https://different-url/")
public interface OtherFeignClient {
    @RequestMapping(...
}

The problem is that the second one is also getting the config from FeignClientConfiguration for some reason. How do we restrict a configuration class to a single feign client?

We have a specific config in FeignClientConfiguration.java:

@Configuration
public class FeignClientConfiguration {
    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new BasicAuthRequestInterceptor(username, password);
    }
}

Then in one feign client in one package we have the following so that it will use the above configuration:

@FeignClient(name = "my-client", url = "https://myurl/", configuration = FeignClientConfiguration.class)
public interface MyFeignClient {

    @RequestMapping(...
}

In a separate feign client, which has a completely different purpose and endpoint, we have:

@FeignClient(name = "some-other-client", url = "https://different-url/")
public interface OtherFeignClient {
    @RequestMapping(...
}

The problem is that the second one is also getting the config from FeignClientConfiguration for some reason. How do we restrict a configuration class to a single feign client?

Share Improve this question asked Nov 25, 2024 at 17:20 John LittleJohn Little 12.2k25 gold badges107 silver badges179 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found a solution. It turns out if you add @Configuration on the feign config class, it adds it to ALL feign clients, regardless.

The solution was to remove @Configuration, then rely on the @FeignClient(..configuration = FeignClientConfiguration.class) to link them.

The popular examples on the internet do both, which appears to be wrong.

发布评论

评论列表(0)

  1. 暂无评论