SpringCloud配置文件中的坑

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect问题

 

版本springcloud 2.1.2

此处本地测试用的单注册中心

eureka配置

采用 .yml 配置方式

# 单例配置
spring:
  application:
    name: arisgo-eureka
server:
  port: 8890
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      default-zone: http://localhost:8890/eureka/

此处注册中心配置的端口号为8890,注册中心指定地址为  http://localhost:8890/eureka

服务提供者配置

eureka:
  client:
    service-url:
      default-zone: http://localhost:8890/eureka/
  instance:
    lease-renewal-interval-in-seconds: 2
    lease-expiration-duration-in-seconds: 4
spring:
  application:
    name: service-user
server:
  port: 8791

启动服务提供者时报错如下:

2019-01-16 10:52:25.002 ERROR 15472 --- [           main] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
	at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
	at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.1.jar:1.19.1]
	at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.9.8.jar:1.9.8]
	at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
	at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
	at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]

问题描述:连接不到地址为 http://localhost:8761/eureka 的注册中心

原因:服务中指定的 http://localhost:8890/eureka 注册中心地址无效,而用了springcloud默认的注册中心地址

修改服务中的配置文件属性 default-zone为defaultZone

尝试了几次:服务提供者配置文件中default-zone属性识别不到,只能识别defaultZone

结论:配置文件中还是以 “驼峰法” 命名较好,不然谁知道下一个坑你会踩在哪里......

你可能感兴趣的:(SpringCloud)