Henu
개발냥발
Henu
전체 방문자
오늘
어제
  • 분류 전체보기 (411)
    • DevOps (52)
      • Kubernetes (19)
      • Docker (14)
      • AWS (3)
      • Nginx (4)
      • Linux (4)
      • ArgoCD (1)
      • CN (2)
      • NATS (0)
      • Git (5)
    • Back-End (30)
      • Django (18)
      • Spring (5)
      • JPA (1)
      • MSA (5)
    • CS (87)
      • SystemSoftware (20)
      • OS (25)
      • Computer Architecture (16)
      • Network (23)
      • Database (2)
    • Lang (21)
      • Java (9)
      • Python (4)
      • C# (8)
    • Life (12)
    • 블록체인 (2)
    • Algorithm (204)
      • BOJ (160)
      • 프로그래머스 (19)
      • LeetCode (4)
      • SWEA (1)
      • 알고리즘 문제 해결 전략 (8)
      • DS, algorithms (7)
      • Checkio (5)
    • IT (2)

블로그 메뉴

  • GitHub
  • 글쓰기
  • 관리자

공지사항

  • Free!

인기 글

태그

  • DFS
  • boj
  • 프로그래머스
  • Network
  • django
  • 백트래킹
  • BFS
  • Kubernetes
  • 다이나믹 프로그래밍
  • docker

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Henu

개발냥발

[Spring] mongoDB Test Error (Error creating bean with name 'embeddedMongoServer' defined in class path resource)
Back-End/Spring

[Spring] mongoDB Test Error (Error creating bean with name 'embeddedMongoServer' defined in class path resource)

2022. 5. 10. 23:18
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-10 23:00:10.030 ERROR 7765 --- [    Test worker] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Unsatisfied dependency expressed through method 'embeddedMongoServer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoConfiguration' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.flapdoodle.embed.mongo.config.MongodConfig]: Factory method 'embeddedMongoConfiguration' threw exception; nested exception is java.lang.IllegalStateException: Set the spring.mongodb.embedded.version property or define your own MongodConfig bean to use embedded MongoDB

위와 같은 에러가 뜨는 경우 해결 방법

 

밑줄 친 부분을 보니 내장 mongoDB를 쓰고 싶으면 spring.mongodb.embedded.version에 대한 property를 설정해주라는 이야기인 듯 하다.

 

찾아보니 spring boot 2.6 이후부터 spring.mongodb.embedded.version은 자동 구성된 임베디드 MongoDB를 사용하도록 설정해야하는것 같다.

 

test 폴더의 하위에 recources 폴더를 만들고

application.yml 파일을 아래와 같이 생성한다.

// test/resources/application.yml

spring:
  mongodb:
    embedded:
      version: 3.3.4

 

문서의 내용을 보면 production에서 사용할 mongodb의 버전과 embedded.mongo의 버전을 동일하게 해주면 된다고 한다.

 

그래서 현재(2022.05.10) 기준 spring data mongo는 3.3.4 버전을 지원하기 때문에 embedded 버전도 3.3.4로 맞춰주었다.

spring 공식문서

 

테스트 해보면 정상 동작할 것이다.

해결!

 

 

2022.05.10
springboot 2.6.7 기준
mongodb.embedded.version 으로 3.3.4, 3.5.5, 3.6.5, latest 등이 사용 가능했다..

 

 

'Back-End > Spring' 카테고리의 다른 글

[Spring] 멀티모듈 단일 프로젝트 구성하기 (gradle)  (0) 2022.06.05
[spring] SpringBoot mongodb 인덱싱 안되는 문제 (SpringBoot mongodb Unique index not created)  (0) 2022.05.11
[Spring] Gradle dependencies 정리  (0) 2022.05.07
[Spring] 전역 REST 컨트롤러 예외 핸들러 만들기  (0) 2022.05.02
    'Back-End/Spring' 카테고리의 다른 글
    • [Spring] 멀티모듈 단일 프로젝트 구성하기 (gradle)
    • [spring] SpringBoot mongodb 인덱싱 안되는 문제 (SpringBoot mongodb Unique index not created)
    • [Spring] Gradle dependencies 정리
    • [Spring] 전역 REST 컨트롤러 예외 핸들러 만들기

    티스토리툴바