Spear A1
Spear A1

Reputation: 585

Spring Eureka looking for default port 8761 instead of custom port

I have a Spring Boot Eureka server app that is configured to run in port 5000 instead of the default one 8761. However when I run the SBA, I get some errors on the console related to java connection refused , while listening to localhost:8761

INFO 10408 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server ERROR 10408 --- [tbeatExecutor-0] 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]

Later when I bring up the other microservices, I can see that they are getting registered in eureka running on port 5000 correctly. But why is the application ignoring the configuration while starting Eureka server at first?

Also as it evident from the picture embedded, the server is looking for registered and unavailable replicas in 8761.

Registered and Unavailable replicas look up at default port

Will highly appreciate any explanations on this.

Upvotes: 3

Views: 15955

Answers (3)

Alexpandiyan Chokkan
Alexpandiyan Chokkan

Reputation: 1075

Please configure the eureka server like below. The eureka server will act as eureka client too. So the server tries to register itself as client and looking for the default port 8761.

server:
  port: 9000

eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:9000/eureka

Upvotes: 3

Spear A1
Spear A1

Reputation: 585

Even after adding the registerWithEureka & fetchRegistry to false, it was still pointing to 8761 for replica url.

eureka.client.registerWithEureka = false 
eureka.client.fetchRegistry = false

The root cause of the problem was not actually setting the self register/search registry properties to be false, but also to modify/specify the correct serviceUrl property.

Added the following lines to the application.properties and now my Eureka server doesn't point to the default Eureka port of 8761 for registered replica url.

eureka.client.serviceUrl.defaultZone: http://localhost:${server.port}/eureka/

Upvotes: 12

Robin Sharma
Robin Sharma

Reputation: 59

Default port for eureka server is 8761 but you can override it using server.port property in application.properties file or application.yml file. 

For e.g.
(application.properties)
   server.port=5000 
(application.yml)
   server:   
    port: 8761

One more thing, you need to specify following properties too to avoid auto registration of eureka.

**application.properties file:-**

eureka.client.registerWithEureka = false
eureka.client.fetchRegistry = false

**application.yml file :-** 

eureka:
   client:
      registerWithEureka: false
      fetchRegistry: false

It should start your application on port 5000. If you still face any issues, just show your properties or yml file code here.

Upvotes: 3

Related Questions