enadim / spring-cloud-ribbon-extensions

Ribbon Extensions - Smart Routing
Apache License 2.0
12 stars 16 forks source link

When i use extensions the consumer can not start up #3

Closed zhaijp closed 6 years ago

zhaijp commented 6 years ago

My springcloud environment is springcloud version : Finchley.RELEASE

First I have add dependency like this

com.github.enadim spring-cloud-ribbon-extensions 2.0.0

Then create RibbonClientsConfig like this @Configuration @EnableRibbonStrictMetadataMatcher public class RibbonClientsConfig {

}

Last create start up class like this

@RibbonClients(defaultConfiguration = RibbonClientsConfig.class) @EnableDiscoveryClient @SpringBootApplication @EnableEurekaClient @EnableContextPropagation public class ConsumerApplication {

@Bean
@LoadBalanced
RestTemplate restTemplate(){
    return new RestTemplate();
}

public static void main(String[] args) {
    SpringApplication.run(ConsumerApplication.class, args);
}

}

After finish the three setps i start up the startup class but it can not startup and the logs is


APPLICATION FAILED TO START


Description:

Parameter 0 of method strictMetadataMatcher in com.github.enadim.spring.cloud.ribbon.support.StrictMetadataMatcherConfig required a bean of type 'com.netflix.client.config.IClientConfig' that could not be found.

Action:

Consider defining a bean of type 'com.netflix.client.config.IClientConfig' in your configuration.

zhaijp commented 6 years ago

@enadim @ouaibsky

enadim commented 6 years ago

this is due to spring boot application that is loading the ribbon config as part of the main application context which is not how it should be. Ribbon loads for each client a specific spring context. consider always defining the RibbonClientsConfig in a distinct package hierarchy than the spring application. for your use case example: package myorg.consumer class ConsumerApplication

package myorg.ribbon class RibbonClientsConfig

zhaijp commented 6 years ago

It works ,Thank you very much @enadim