
개인적으로, 문자열 오타나 이런 의존성 문제가 제일 잡기 힘든 것 같다.
힘들기를 넘어서 약간 그냥 모든걸 포기하고 싶은 느낌?
오타는 그냥 프로젝트 새로 밀고 다시할까? 라는 생각이 들기라도 하지만 의존성 문제는 사실 해결하기가 어렵기 때문에, 처음부터 잘 설정하고 시작하는 것이 가장 베스트 프랙티스인 것 같다.
문제 상황
SQL Mapper 로 JDBC 기술을 사용하다가 처음으로 MyBatis를 적용하면서 문제가 발생하였다.
이번에는 의존성 관련 문제다보니 코드 내용은 생략하고 실제 문제가 되는 부분을 위주로 기록한다.
처음에 테스트를 돌렸을 때 다음과 같이 오류가 발생했다.
Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248)
Caused by: java.lang.IllegalArgumentException:
Unable to instantiate org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector
[org.mybatis.spring.boot.autoconfigure.MybatisDependsOnDatabaseInitializationDetector]
Caused by: java.lang.UnsupportedClassVersionError:
org/mybatis/spring/boot/autoconfigure/MybatisDependsOnDatabaseInitializationDetector has been compiled by a more recent version of the Java Runtime (class file version 61.0),
this version of the Java Runtime only recognizes class file versions up to 55.0
여기서 보면 가장 밑에 라인에 ~mybatis 경로의 리소스가 자바 런타임의 가장 최근 버전으로 컴파일 되었다 어쩌구 저쩌구 라는 에러와 함께 그 바로 윗줄에 depencency 어쩌구 저쩌구 하면서 느낌상 스프링부트와 버전이 호환되지 않는다 ~ 라는 식으로 얘기하고 있는 것 같았다.
그래도 가장 위 에러인 ApplicationContext예외를 보고 구글링을 때렸는데 사실 찾아야하는 범위가 너무나 많았고, 블로그들에 틀린 글들도 너무나 많았다.
그래서 일단 나의 직감을 믿고, 의존성 부분을 확인해보고자 했다.
plugins {
id 'org.springframework.boot' version '2.6.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
//JdbcTemplate 추가
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
//H2 데이터베이스 추가
runtimeOnly 'com.h2database:h2'
//MyBatis 추가
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//테스트에서 lombok 사용
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
}
tasks.named('test') {
useJUnitPlatform()
}
문제 해결
이전에 JDBC 기술을 사용했을 때는 문제 없이 컴파일 되었기 때문에, myBatis의 문제라고 생각하고 myBatis 공식 레퍼런스를 찾아보기 시작했다.
https://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/
Introduction – mybatis-spring-boot-autoconfigure
Using the SpringBootVFS The MyBatis-Spring-Boot-Starter provides the SpringBootVFS as an implementation class of VFS. The VFS is used for searching classes (e.g. target class of type alias, type handler class) from an application (or application server). I
mybatis.org

사진이 잘 안보여서 링크를 참조했다.
잘 보면, 스프링부트가 3.0 버전 이상이라면 마이 바티스를 3.0 버전을 사용해야하고, 스프링부트가 2.3 버전이면 2.1버전을 사용해라 ~ 라고 친절하게 알려준다.
나의 스프링부트는 2.6 버전이었기에, EOL 이지만 2.2 버전을 사용해야했다.
그래서 다음처럼 마이 바티스 2.2.0 버전을 수정했다.
//MyBatis 추가
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.0'
이후 문제 없이 동작했다. 결과 사진은 생략한다.
습관 : 항상 공식 문서 먼저 보자
구글링을 통해 자료를 검색하기엔 너무 많은 시간과 노력이 소모된다.
특히 이런 경우, JDBC로는 잘 동작했던 것을 확인했기에 무조건 MyBatis문제라고 생각했고, MyBatis 공식 레퍼런스를 확인해서 다행히 빠르게 해결할 수 있었다.
앞으로도 이런 관련 문제가 발생하면 그대로 긁어서 AI에게 물어보기보단 공식 레퍼런스를 보는 습관을 키우도록 하자.
'Error' 카테고리의 다른 글
| [Spring] 애플리케이션 실행시 data.sql / schema.sql 이 실행되지 않을 때 (0) | 2025.10.16 |
|---|---|
| Mac에서 Notion 한글 씹힐 때 (0) | 2025.10.07 |
| [Java] properties 파일에 등록한 메시지들이 깨질 때 (0) | 2025.07.11 |
| [Spring] 며칠 굶은 것 같이 부실한 로그 (0) | 2025.06.16 |
| [Spring] 제 마음을 읽고 문자열도 컴파일 오류 내주세요 (0) | 2025.05.31 |