Spring Boot Microservices: ‘Service Unavailable’ Error when Accessing Endpoint via API Gateway

I’m working on a Spring Boot microservices application and have dockerized all the services. While all the services appear to be running, I’m encountering an issue when trying to access the endpoints via the API Gateway.

Error Message:

{
    "timestamp": "2024-06-24T14:01:32.938+00:00",
    "path": "/departments",
    "status": 503,
    "error": "Service Unavailable",
    "requestId": "1a88ca39-1"
}

Problem Description:
The Eureka server (service-registry) only registers the API Gateway and not the other services (department-service, employee-service, and project-service). This makes me think that the API Gateway can’t find the services, or the services are not set up correctly to fetch the configuration from the config-server which is other independent service.

Configuration Files:

Service Registry (Eureka) Config:

server:
  port: 8761

spring:
  application:
    name: service-registry

eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    serviceUrl:
      defaultZone: http://service-registry:8761/eureka/

API Gateway Config:

server:
  port: 8060

eureka:
  client:
    serviceUrl:
      defaultZone: http://service-registry:8761/eureka/

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        - id: employee-service
          uri: lb://employee-service
          predicates:
            - Path=/employees/**
        - id: department-service
          uri: lb://department-service
          predicates:
            - Path=/departments/**
        - id: project-service
          uri: lb://project-service
          predicates:
            - Path=/projects/**

Department Config:

spring:
  application:
    name: department-service

  config:
    import: "optional:configserver:http://config-server:8088"

Employee and Project Config is just same with department just different app name:

Config Server Config:

server:
  port: 8088

spring:
  application:
    name: config-server
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/config

Config Server Department Config:

eureka:
  client:
    serviceUrl:
      defaultZone: http://service-registry:8761/eureka/

spring:
  application:
    name: department-service
  datasource:
    url: jdbc:jdbc:postgresql://postgres:5432/microservice_comp_data
    username: postgres
    password: password
    driver-class-name: org.postgresql.Driver
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate:
        format_sql: true
    database: postgresql
    database-platform: org.hibernate.dialect.PostgreSQLDialect

server:
  error:
    include-message: always
  port: 8081


management:
  tracing:
    sampling:
      probability: 1.0

Config Server Employee and Project is just same with department just different app name:

Docker Compose:

version: '3.8'
services:
  config-server:
    build:
      context: ./config-server
    ports:
      - "8088:8088"

  service-registry:
    build:
      context: ./service-registry
    ports:
      - "8761:8761"
    depends_on:
      - config-server

  department-service:
    build:
      context: ./department-service
    ports:
      - "8081:8081"
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/microservice_comp_data
      SPRING_DATASOURCE_USERNAME: postgres
      SPRING_DATASOURCE_PASSWORD: password
    depends_on:
      - service-registry
      - postgres

  employee-service:
    build:
      context: ./employee-service
    ports:
      - "8082:8082"
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/microservice_comp_data
      SPRING_DATASOURCE_USERNAME: postgres
      SPRING_DATASOURCE_PASSWORD: password
    depends_on:
      - department-service

  project-service:
    build:
      context: ./project-service
    ports:
      - "8083:8083"
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/microservice_comp_data
      SPRING_DATASOURCE_USERNAME: postgres
      SPRING_DATASOURCE_PASSWORD: password
    depends_on:
      - employee-service

  api-gateway:
    build:
      context: ./api-gateway
    ports:
      - "8060:8060"
    depends_on:
      - service-registry

  postgres:
    image: postgres:latest
    container_name: postgres-container
    environment:
      POSTGRES_DB: microservice_comp_data
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
    ports:
      - "5431:5432"

  zipkin:
    image: openzipkin/zipkin
    ports:
      - "9411:9411"

I’ve double-checked the configurations and logs, but I can’t seem to pinpoint the issue. Any guidance on what might be wrong or how to properly configure these microservices would be greatly appreciated.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật