갓생사는 김초원의 개발 블로그
chocho_log
갓생사는 김초원의 개발 블로그
전체 방문자
오늘
어제
  • 분류 전체보기 (78)
    • 개발 (23)
      • Spring (4)
      • Java (4)
      • Database (2)
      • Elasticsearch (3)
      • ETC (3)
      • JPA (3)
      • 이슈 (1)
    • 코딩 테스트 (43)
      • 프로그래머스 (23)
      • 백준 (12)
      • TIP (8)
    • 자료구조 (2)
    • 알고리즘 (4)
    • 잡생각 (0)
    • 경험 (5)
      • AWS re:Invent 2024 (5)

블로그 메뉴

    공지사항

    인기 글

    태그

    • 디자인패턴 #SOLID 원칙
    • Lazy Loading
    • querydsl
    • Spring Boot Embedded Tomcat
    • jpa
    • 지연로딩
    • jar
    • war

    최근 댓글

    최근 글

    갓생사는 김초원의 개발 블로그

    chocho_log

    [Junit] java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test 에러
    개발/이슈

    [Junit] java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test 에러

    2021. 1. 24. 15:43

    junit5에서 단위테스트 초기 세팅 과정에서 다음과 같은 에러메시지를 뱉었다. 

    java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration
    or @SpringBootTest(classes=...) with your test

     

    @SpringBootApplication 어노테이션이 붙은 클래스가 위치한 패키지의 하위 패키지에 테스트를 둬야 한다는 원칙을 어긴 것이다.

    나의 경우에는 멀티모듈 프로젝트였고 테스트코드를 작성하는 모듈은 @SpringBootApplication 어노테이션이 붙은 클래스가 존재하지 않는 단순참조용 모듈이었다. 

     

    다음과 같은 구조였다.

     

     

    문제해결:

    Test.class 가 있는 패키지에 임의로 @SpringBootApplication 어노테이션이 붙은 클래스를 따로 생성해줬다. 

    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class TestApplication {
    }
    

     

     

     

     

     

    참고

    www.baeldung.com/spring-boot-unable-to-find-springbootconfiguration-with-datajpatest

      갓생사는 김초원의 개발 블로그
      갓생사는 김초원의 개발 블로그
      갓생사는 김초원의 개발 블로그 github: https://github.com/kimchowon

      티스토리툴바