0

I'm following this article (http://www.baeldung.com/spring-cloud-netflix-eureka) to set up eureka, my application.yml looks like this

server:
    port: 8761
eureka:
    client:
        registerWithEureka: false
        fetchRegistry: false
        serviceUrl:
            defaultZone: http://${eureka.instance.hostname}:${server.port}

but I debug the main application I always get:

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.4.10.jar:1.4.10]

and when I got to my browser eureka is not in 8761 port but in 8080 port instead, what I'm doing wrong?

Cœur
  • 37,241
  • 25
  • 195
  • 267
fquirogam
  • 19
  • 7

1 Answers1

1

You can't referece a property you just set above. This is not a procedural script, there's no guarantee the eureka line will be executed before the server one so ${server.port} will be the defaut: 8080

If you run you app using an environment prop it will work. Try:

java -Dserver.port=8761 -jar your-app.jar

Raphael
  • 1,760
  • 1
  • 12
  • 21
  • but I'm not starting any server, plus in the other examples I saw this problem seems not to exist – fquirogam Mar 17 '18 at 06:28
  • Replace `http://${eureka.instance.hostname}:${server.port}` with this: `http://localhost:8761` or if the eureka server is not running on localhost, use the correct IP or dns . – Raphael Mar 19 '18 at 14:51