I am trying to use a feign configuration to create a custom feign with keystore defined.
public class FeignConfiguration extends FeignConfigurationBase {
public FeignConfiguration() {
}
@Bean
public Client feignClientCertAuth(ApplicationContext ctx, LoadBalancerClient loadBalancerClient, @Nullable LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerProperties properties, LoadBalancerClientFactory loadBalancerClientFactory) {
String keystore = this.getKeystore(ctx);
String keystorePwd = this.getKeystorePwd(ctx);
SSLSocketFactory sslSocketFactory = this.feignSSLContext(ctx, keystore, keystorePwd);
return this.feignClient(ctx, loadBalancerClient, properties, loadBalancerClientFactory, loadBalancedRetryFactory, sslSocketFactory);
}
}
I want this feignClient to be used in some other class
@Import(FeignConfiguration.class)
class FeignClientHelper{
@Autowired
Client feignClient;
}
This is working good for me, but the same ssl context is used for other requests in the project also.
I suspect the issue is that, when I am importing FeignConfiguration class, the feignClient is stored in spring context and the feign is using that for other request also.
what I want is to have feignClient available in the above class but not globally accessible to the spring context, so that other feign request wont be using that.
Any help on this is appreciated.
You can use named beans, so define the beans with different names, the below snippet shows one.
@Bean("certFeign")
public Client feignClientCertAuth(ApplicationContext ctx, LoadBalancerClient loadBalancerClient, @Nullable LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerProperties properties, LoadBalancerClientFactory loadBalancerClientFactory) {
String keystore = this.getKeystore(ctx);
String keystorePwd = this.getKeystorePwd(ctx);
SSLSocketFactory sslSocketFactory = this.feignSSLContext(ctx, keystore, keystorePwd);
return this.feignClient(ctx, loadBalancerClient, properties, loadBalancerClientFactory, loadBalancedRetryFactory, sslSocketFactory);
and use the bean with @Qualifier annotation where ever you want this bean
@Import(FeignConfiguration.class)
class FeignClientHelper{
@Autowired
@Qualifier("certFeign")
Client feignClient;
}
1