Docker-Compose를 사용하면서, ElasticSearch보다 Spring Boot가 먼저 실행을 마쳤을 때

작은곰·2025년 1월 15일
0

TIL

목록 보기
2/2

Caused by: org.springframework.dao.DataAccessResourceFailureException: Connection refused

ElasticSearch(ES)와 Spring boot를 묶었을 때 아래와 같이 docker-compose.yml를 작성할 수 있다.

elasticsearch가 실행된 후 Spring boot를 실행했으나, ES와의 연결을 성공하지 못해 오류가 발생한다. 맨 위 에러 메시지 위로 올라가다 보면 아래와 같은 오류 메시지를 볼 수 있을 것이다.

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception

ES가 정상적으로 동작하는 지 확인 한 후, Spring Boot를 실행하도록 하자.

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
    container_name: elasticsearch
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=false
    ports:
      - "9200:9200"
    networks:
      - elk_network
    healthcheck:
      test: [ "CMD-SHELL", "curl -fsSL http://localhost:9200/_cluster/health || exit 1" ]
      interval: 10s
      timeout: 5s
      retries: 5

  springboot-app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: springboot-app
    environment:
      - SPRING_PROFILES_ACTIVE=dev
    ports:
      - "8080:8080"
    networks:
      - elk_network
    depends_on:
      elasticsearch:
        condition: service_healthy
profile
growing?

0개의 댓글

관련 채용 정보