// 接口 @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
解决了吗?我也遇到和你同样的问题,试了很多方法,不行,还是找不到原因
解决了,我的问题是在使用feign远程调用时候调不同,原因是服务名称不能用下划线,换成中划线。