首页 新闻 赞助 找找看

springcloud搭建的微服务,在远程调用的时候,无法以服务名来对服务提供的接口进行访问

0
[待解决问题]
// 接口
@RestController
public class ConsumerController {

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping(value = "/ribbon-consumer", method = RequestMethod.GET)
    public String helloConsumer() {
        return restTemplate.getForEntity("http://micro_server/hello", String.class).getBody();
    }

}

配置

server:
  port: 8888 
 
spring:
  application:
    name: micro_server
         
eureka:
  client:
    fetchRegistry: true 
    registerWithEureka: true   
    service-url:
      defaultZone: http://localhost:9999/eureka/

    

全部启动后,在eurake注册中心能看到注册成功的服务,但是调用接口的时候报错:

复制代码
java.lang.IllegalStateException: Request URI does not contain a valid hostname: http://micro_server/hello
    at org.springframework.util.Assert.state(Assert.java:70) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:54) ~[spring-cloud-commons-1.2.3.RELEASE.jar:1.2.3.RELEASE]
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:86) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.cloud.netflix.metrics.MetricsClientHttpRequestInterceptor.intercept(MetricsClientHttpRequestInterceptor.java:64) ~[spring-cloud-netflix-core-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.ex
复制代码
人间四月的主页 人间四月 | 菜鸟二级 | 园豆:206
提问于:2017-10-24 18:21
< >
分享
所有回答(1)
0

解决了吗?我也遇到和你同样的问题,试了很多方法,不行,还是找不到原因

狂野心情 | 园豆:202 (菜鸟二级) | 2018-01-28 00:05

解决了,我的问题是在使用feign远程调用时候调不同,原因是服务名称不能用下划线,换成中划线。

支持(0) 反对(0) 合取 | 园豆:200 (初学一级) | 2018-01-28 00:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册