开发者社区> 问答> 正文

ribbon测试出错No instances available for XC-?400报错

一个简单的测试:使用eureka+ribbon访问服务。配置都配好了,实在不知道问题出在哪儿。。。

1.服务端

1.1服务端注解:@EnableEurekaClient

1.2服务端配置

server:
  port: ${PORT:31001}
spring:
  application:
    name: xc-service-manage-cms
eureka:
  client:
    register-with-eureka: true
    fetch-registry: false
    service-url:
      defaultZone: ${EUREKA_SERVER:http://localhost:50101/eureka/}
  instance:
    prefer-ip-address: true
    ip-address: ${IP_ADDRESS:127.0.0.1}
    instance-id: ${spring.application.name} :${server.port}

2.客户端

2.1注解

2.2配置

server:
  port: 31200
spring:
  application:
    name: xc-service-manage-course
eureka:
  client:
    register-with-eureka: true
    fetch-registry: false
    service-url:
      defaultZone: ${EUREKA_SERVER:http://localhost:50101/eureka/}
  instance:
    prefer-ip-address: true
    ip-address: ${IP_ADDRESS:127.0.0.1}
    instance-id: ${spring.application.name} :${server.port}
ribbon:
  MaxAutoRetries: 2
  MaxAutoRetriesNextServer: 3
  OkToRetryOnAllOperations: false
  ConnectTimeout: 5000
  ReadTimeout: 6000

3.Eureka注册中心页面

服务和客户端都注册进去了

4.测试代码

@SpringBootTest(classes = ManageCourseApplication.class)
@RunWith(SpringRunner.class)
public class TestRibbon {
    @Autowired
    RestTemplate restTemplate;
    @Test
    public void test(){
        String serviceId="XC-SERVICE-MANAGE-CMS";
        ResponseEntity<CmsPage> forEntity = restTemplate.getForEntity("http://"+serviceId+"/cms/manage/get/5a754adf6abb500ad05688d9", CmsPage.class);
        CmsPage body = forEntity.getBody();
        System.out.println(body);
    }
}

报错:

java.lang.IllegalStateException: No instances available for XC-SERVICE-MANAGE-CMS

	at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:89)
	at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:55)
	at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
	at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:76)

 

展开
收起
爱吃鱼的程序员 2020-06-05 14:15:58 2269 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        <p>大兄弟,eureka服务端注解是@EnableEurekaServer,客户端注解是@EnableEurekaClient。</p> 
    

    大兄弟注意区别!

    我也在做这个项目,也是在Spring Cloud卡主,你bug我知道原因,我的bug就不知道什么原因了!

    ……做这个项目都是坎,不容易,大兄弟加油……

                            你好,我在eureka这块也卡住了,服务者注册到了eureka,消费者可以通过discoveryClient.getServices()获取到serviceNames,但是discoveryClient.getInstances(serviceName)却获取不到服务实例,是空,可能是那些方面的原因?
                        
    
                        <p>我和你一样在这里出错了,解决了吗?</p>
    
    2020-06-05 14:16:10
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
移动互联网测试到质量的转变 立即下载
给ITer的技术实战进阶课-阿里CIO学院独家教材(四) 立即下载
F2etest — 多浏览器兼容性测试整体解决方案 立即下载