아래 가이드 페이지는 훌륭하고 스프링 부트 응용 프로그램의 리본에 대한 기본 사례로 사용됩니다. 예 -@LoadBalanced Rest 중첩 된 컨텍스트 끝점을 호출하는 템플릿
https://spring.io/guides/gs/client-side-load-balancing/
예 자마자 엔드 매핑 중첩됨에 따라 작동하지
@RequestMapping을 추가 (값 = "/ 오신 것을 환영합니다") 클래스 수준에서
@RestController
@SpringBootApplication
@RequestMapping(value = "/welcome") //<------------- ADDED --->
public class SayHelloApplication {
private static Logger log = LoggerFactory.getLogger(SayHelloApplication.class);
@RequestMapping(value = "/greeting")
public String greet() {
그리고
String greeting = this.restTemplate.getForObject("http://say-hello/greeting", String.class);
에서 클라이언트의 @LoadBalanced RestTemplate 통화를 변경
to
String greeting = this.restTemplate.getForObject("http://say-hello/welcome/greeting", String.class);
직접적으로 http://localhost:8090/welcome/greeting을 처리하는 것이 정상적으로 작동하는 동안 연결된 스택 추적으로는 호출이 실패합니다. domain.com/x/y/z/p/q와 같이 길고 중첩 된 URL 끝점에 요청을로드하도록 리본을 구성하는 적절한 방법은 무엇입니까?
스택 트레이스 :
java.lang.IllegalStateException: No instances available for say-hello
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:79) ~[spring-cloud-netflix-core-1.1.4.RELEASE.jar:1.1.4.RELEASE]
at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:46) ~[spring-cloud-commons-1.1.1.RELEASE.jar:1.1.1.RELEASE]
at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:85) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:69) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:596) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:264) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at hello.UserApplication.hi(UserApplication.java:31) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
리본 만 호스트 이름을 처리합니다. 당신의 오류는 리본이 say-hello에 대한 인스턴스를 찾을 수 없다고 말합니다. 다시 시도 했습니까? 조금 걸릴 수 있습니다. – spencergibb
say-hello 서비스에 등록 된 인스턴스가 있는지 확인하려면 Eureka를 확인하십시오. –
라이브러리 및 주어진 링크에 대한 예제 코드에 따라 say-hello.ribbon.eureka.enabled = false. 나는 그 질문에 명시된 변경만을했다. 주어진 URL이 http : // say-hello/context (예제가 작동)이지만 http : // say-hello/context/sub-context/(스택이 아닌 경우) 일 때만 호스트 이름을 처리하는 것으로 보입니다. trace) – nmadzharov