skip to Main Content

For some reason it does not seem like application.yml is correctly read in my spring boot application. No matter what I try with the application tries to connect to eureka on local host.

spring:
  application:
    name: oneminute-dashboard
  server:
    port: 5001
  eureka:
    client:
      service-url:
        defaultZone: http://eureka-server:8761/eureka
  sql:
    init:
      platform: postgres
  datasource:
    url: jdbc:postgresql://db:5432/dev_onemin_percent
    username: xxxx
    password: xxxx
  jpa:
    hibernate:
      ddl-auto: update
    database-platform: org.hibernate.dialect.PostgreSQLDialect

Looking at the log I see that it tries to connect to localhost. I have the same problem with postgres but there the datasource can be overridden from the docker-compose file.

oneminute_dashboard    | 2022-08-02 10:09:58.069  WARN 1 --- [  restartedMain] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused
oneminute_dashboard    | 2022-08-02 10:09:58.069  INFO 1 --- [  restartedMain] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_ONEMINUTE-DASHBOARD/01bd8154c292:oneminute-dashboard:5001 - was unable to refresh its cache! This periodic background refresh will be retried in 30 seconds. status = Cannot execute request on any known server stacktrace = com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

docker compose below

version: '3.8'

services:
  oneminute_dashboard:
    image: xyz/oneminute_dashboard:latest
    container_name: oneminute_dashboard
    environment:
      - SPRING_PROFILES_ACTIVE=docker
      - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/dev_onemin_percent
    ports:
      - "5001:5001"
    expose:
      - 5001
    networks:
      - IB
    depends_on:
      - eureka-server

2

Answers


  1. This documentation uses serviceUrl instead of service-url
    https://cloud.spring.io/spring-cloud-static/Edgware.SR6/multi/multi__service_discovery_eureka_clients.html

    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    
    Login or Signup to reply.
  2. It will be

    default-zone: http://eureka-server:8761/eureka
    

    and not

    defaultZone: http://eureka-server:8761/eureka
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search