2017-05-17 7 views
1

@FeignClientに使用するサーバーのリストを構成できません。私はSpring Cloud Netflixを使用していますが、この特定のサービス(foo-service)はユーレカに登録しません。このため、YMLファイルにfoo-serviceのサーバのリストを設定する必要があります。@FeignClientをサーバーのリストで構成できません

ただし、listOfServersは決して読み込まれないため、Feign/Ribbonは使用する単一のサーバーを持たないため、操作は失敗します。

私はここで間違っていますか?

マイ装うクライアント:bootstrap.ymlで

@FeignClient(name="foo-service") 
public interface FooFeignClient { 

    @RequestMapping(value = "/perform-check", method = POST) 
    ResponseEntity<FooResponse> performCheck(FooRequest fooRequest); 

} 

装うクライアントは春のブートアプリケーションで設定されているどのよう
foo-service: 
    ribbon: 
     eureka: 
     enabled: false 
     listOfServers: foobox1,foobox2,foobox3 

@SpringBootApplication 
@EnableEurekaClient 
@EnableDiscoveryClient 
@EnableHazelcastClient 
@EnableFeignClients 
@RibbonClients({ 
    @RibbonClient(name = "foo-service", configuration = MyApp.FooServiceRibbonConfig.class) 
}) 
public class MyApp { 

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

    .... 

    @Configuration 
    static class FooServiceRibbonConfig { 

     @Bean 
     @ConditionalOnMissingBean 
     public IClientConfig ribbonClientConfig() { 
     DefaultClientConfigImpl config = new DefaultClientConfigImpl(); 
     config.loadProperties("foo-service"); 
     return config; 
     } 

     @Bean 
     ServerList<Server> ribbonServerList(IClientConfig config) { 
     ConfigurationBasedServerList serverList = new ConfigurationBasedServerList(); 
     serverList.initWithNiwsConfig(config); 
     return serverList; 
     } 
    } 
} 
+0

'listOfServers'は大文字と小文字を区別し、' ListOfServers'である必要があります。 – spencergibb

+0

@spencergibb 'ListOfServers'も機能しませんでした。私はここのアドバイスに従うことを試みたhttps://github.com/spring-cloud/spring-cloud-netflix/issues/325 – vegemite4me

+0

問題を再現するサンプルプロジェクトを提供する必要があります。 – spencergibb

答えて

0

に最も簡単な方法あなたのニーズを実現するには..

あなたのコードでは、以下のようにFooServiceRibbonConfigに関連するすべてのコードを削除してください。

@SpringBootApplication 
@EnableEurekaClient 
@EnableDiscoveryClient 
@EnableHazelcastClient 
@EnableFeignClients 
}) 
public class MyApp { 

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

次に、以下のようにプロファイルファイルを変更します。あなたがやったように

foo-service: 
    ribbon: 
     NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList 
     listOfServers: foobox1,foobox2,foobox3 

ribbonServerList Beanを定義すると、それを実現するための別の方法である、と私はあなたのコードが実行されていない理由はわかりません。私の場合、あなたのような同様のコードはうまくいきます。しかし、簡単な方法がありますので、試してみてください。

+0

私は同じ例外を受け取ります:java.lang.RuntimeException:com.netflix.client.ClientException:ロードバランサはクライアントのために利用可能なサーバを持っていません:foo-service'。まるでYMLファイルがまったく読み込まれないかのようです。 – vegemite4me

関連する問題