Backend/Spring
SpringBoot - MySQL 연결하도록 설정하고 난 이후에 프로젝트 실행시 에러 발생한다면?
out of coding
2022. 12. 9. 22:43
MySQL을 프로젝트에 연결하고 프로젝트 실행을 했는데 다음과 같은 에러가 발생하게 된다면?
저는 다음과 같은 에러를 만났습니다.
caused by: 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.jdbc.driver |
원인은 dataSource 연결 문제. MySQL이나 MyBatis등 DB 관련 설정을 추가하고 나서 build gradle에 제대로 추가를 안해주어서 그렇습니다.
다음을 추가하여주어 봅니다.
그래도 안된다면 다른 dependencies를 추가하여 주어야 합니다.
dependencies {
.....
implementation("mysql:mysql-connector-java")
.....
}