Search code examples
springconfigjavabeansnetflix-ribbon

How to create Bean with IClientConfig


How do I create a @Bean for IClientConfig? I need to initialize the ribbonLoadBalancingHttpClient bean with a pre-configured httpclient delegate argument. The problem is that the constructor required by the IClientConfig bean is not loaded in the context.

This is not working to initialize the IClientConfig:

IClientConfig.Builder.newBuilder().build();

UPDATE I found that every IClientConfig is related to a clientName If I hardcoded one clientName (for e.g. "name") ribbon will always return information for clientName -> "name".

But I have more than one clientName:

 nameone:
    ribbon:
       listOfServers:
          localhost:1110

 nametwo:
    ribbon:
       listOfServers:
          localhost:1111

 namethree:
    ribbon:
       listOfServers:
          localhost:1112

 namefour:
    ribbon:
       listOfServers:
          localhost:1113
       IsSecure: true

 namefive:
    ribbon:
       listOfServers:
          localhost:1114

 namesix:
    ribbon:
       listOfServers:
          localhost:111

So I override the @Bean for ribbonLoadBalancingHttpClient but the IClientConfig must be also put in the context for every clientName. How can I achieve that?

If you wonder why I want to use a custom HttpClient, it's to switch off self signed certification validation for ribbon client. If there's another approach, then that's also a valid answer.


Solution

  • I find a answer in github asked by me : https://github.com/spring-cloud/spring-cloud-netflix/issues/1776