문제상황:
Spring Boot 프로젝트에서 자주 발생하는 에러 중 하나는 "Cannot determine embedded database driver class" 에러입니다. 이 예시에서는 실무에서 사용될 수 있는 코드를 사용하여 이 에러를 재현하고 해결해보겠습니다.
아래는 에러가 발생한 코드와 이에 대한 설명입니다.
application.properties 파일:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
이 코드에서 발생한 에러 로그는 다음과 같습니다.
Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
해결방법:
에러가 수정된 코드와 수정된 부분에 대한 주석을 확인해봅시다.
application.properties 파일:
# 데이터베이스 드라이버 클래스 추가
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
원인분석:
이 에러는 Spring Boot가 내장 데이터베이스 드라이버 클래스를 결정하지 못하여 발생합니다. 이 경우에는 H2 데이터베이스를 사용하려고 했지만, 드라이버 클래스를 지정하지 않아서 발생한 문제입니다.
이 문제의 해결 방법은 다음과 같습니다.
- application.properties 파일에 데이터베이스 드라이버 클래스를 지정합니다.
이렇게 하면 Spring Boot는 데이터베이스 드라이버 클래스를 찾을 수 있으며, 올바르게 데이터베이스 연결을 설정할 수 있습니다.
참고링크:
728x90