스프링 mysql 연동 에러
java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver 해결
진짜 5시간 걸려서 해결했다...😭
5시간 어쩌면 짧을수도 있지만, 그중 4시간은 찾는 내내 똑같은 답변들만 나와서 미치는줄..
스프링 김영한님의 강의를 다 보고 혼자 실습을 해보는데, 데이터 베이스 h2를 깔고싶지 않아서 이미 있던 mysql로 쓰려고 했다. 다른 블로그들을 참고하며 잘 따라 갔지만 에러.
jar파일이 잘 있느냐,
8.0 이상이고 com.mysql.cj.jdbc.Driver 중간에 cj잘 들어 갔느냐,
환경변수 설정이 잘 되었느냐,
뒤에 띄어쓰기 없느냐
진짜 별의 별거 다해봤다. 심지어 mysql도 버전이 두개 깔려 있어서 다 지우고 8.0.32로 다시 깔았다.
근데도 안돼서 계속 삽질하던 중 한줄기 빛 등장
https://skyriv312079.tistory.com/35
[Spring] Spring boot와 Mysql 연동 (Gradle)
스프링을 이용해 공부를 하면서 기존에는 H2 데이터베이스를 사용하다가 Mysql을 사용해서 연결을 해보려고 한다. application.properties과 build.gradle의 파일을 비교 변경하면서 진행하려고 한다. build.g
skyriv312079.tistory.com
이전 오류는 모르겠으나 내가 새로 받은 mysql 8.0.32 때문인지, 순전히 스프링의 버전 때문인지 어쨋든 mysql connection문이 바뀌었다.
implementation 'org.springframework.boot:spring-boot-starter'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
build.gradle > dependencies 부분에 해당 코드를 넣었더니 됐다.
전체 모습은
build.gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'com.h2database:h2'
implementation 'org.springframework.boot:spring-boot-starter'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
application.properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springtest?
serverTimezone=UTC&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=____
배고프다