2017-05-17 23 views
1

@FeignClient에 사용할 서버 목록을 구성 할 수 없습니다. Spring Cloud Netflix를 사용하고 있지만이 특정 서비스 (foo-service)는 Eureka에 등록하지 않습니다. 이러한 이유로 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); 

} 

:

@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

가장 쉬운 방법으로 다음 척하기 클라이언트가 봄 부팅 응용 프로그램에서 구성되는 방법

foo-service: 
    ribbon: 
     eureka: 
     enabled: false 
     listOfServers: foobox1,foobox2,foobox3 

귀하의 요구를 실현하십시오 ..

코드에서 아래와 같이 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 빈을 정의하는 것은 그것을 달성하는 또 다른 방법입니다, 나는 코드가 실행되지 않는 이유를 모르겠어요. 제 경우에는 비슷한 코드를 사용하는 것이 좋습니다. 그러나 쉬운 방법이 있으므로 시도하십시오.

+0

동일한 예외가 발생합니다 : java.lang.RuntimeException : com.netflix.client.ClientException :로드 밸런서에 클라이언트 : foo-service' 서버가 없습니다. 마치 YML 파일을 전혀 읽지 않는 것과 같습니다. – vegemite4me