jomalone_jia
jomalone_jia

Reputation: 53

spring cloud eureka UnknownHostException

Here is my eureka yml:

eureka:
  instance:
    hostname: eureka
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://eureka:8761/eureka/
  server:
    waitTimeInMsWhenSyncEmpty: 0

And here is my zuul server yml eureka part:

eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka:8761/eureka/

When I registry the zuul server to eureka , it throws java.net.UnknownHostException: eureka

If I change the zuul server yml to defaultZone: http://localhost:8761/eureka/ it would be deployed successfully, so how can I use 'eureka' host replace localhost, can somebody help me?

Upvotes: 1

Views: 1856

Answers (2)

Fahim Farook
Fahim Farook

Reputation: 1483

If I change the zuul server yml to defaultZone: http://localhost:8761/eureka/ it would be deployed successfully

Which means you have deployed Eureka server on your local machine. If you want to use eureka as hostname, you can change your hostname to eureka.

Or may be you meant to use ${eureka.hostname}. The documentation says;

${eureka.hostname} is a native placeholder only available in later versions of Eureka. You could achieve the same thing with Spring placeholders as well, e.g. using ${eureka.instance.hostName}

Upvotes: 1

Arthur Wu
Arthur Wu

Reputation: 151

You can try adding "127.0.0.1 eureka" to your hosts file.

Upvotes: 1

Related Questions