[오늘의 에러] Spring Boot "Cannot load driver class: com.mysql.cj.jdbc.Driver"

서지혜·2023년 4월 13일
0

TIL

목록 보기
2/22

기록일 : 2023년 04월 13일
해결 난이도 : 🌞 쉬움


🧨 개요

DPIC 프로젝트 Static Manager 코드 작성 중 발생한 문제이다.
Docker에 MySQL을 설치하고 Spring Boot 프로젝트와 연동하려고 하던 도중 Spring Boot 프로젝트를 Run 했을 때 아래와 같은 에러가 발생했다.

2023-04-13 12:34:44.863 ERROR 14796 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourcePoolMetadataMeterBinder' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration$DataSourcePoolMetadataMetricsConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourcePoolMetadataMeterBinder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver 

데이터베이스와 연결이 제대로 되지 않았을수도 있다는 것을 알고 Connection을 생성해 보았으나 연결은 제대로 되었다.

🧨 해결

application.property의 설정을 다시 확인해보니 spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver 뒤에 공백이 있었다. 공백을 제거하면 프로젝트가 제대로 실행된다.

[참고 블로그]
https://www.inflearn.com/questions/94737/%EC%88%9C%EC%88%98-jdbc-%EC%97%90%EC%84%9C-%EC%BD%94%EB%93%9C-%EC%9E%85%EB%A0%A5%ED%9B%84-%EC%8B%A4%ED%96%89%EC%8B%9C-%EC%97%90%EB%9F%AC
https://solbel.tistory.com/2220

profile
개발자가 되고 싶은 감자

0개의 댓글

관련 채용 정보