강의에서 스프링 2.x.x버전과 자바 11, h2데이터베이스를 사용하는데 다르게 설정하다가 우여곡절이 많았다..
세팅한 몇가지 부분을 서술하겠다.
1. 기본 세팅
os : Window 11
64bit 운영체제
Gradle-groovy, Java 17, 3.0.5
Dependencies : Spring Web, Spring data JPA, Thymeleaf, Lombok
버전 : mysql 8.0.32
2. Mysql Workbench 설정
CREATE DATABASE test_db;
CREATE USER 'tester'@'localhost' identified BY 'test';
GRANT ALL PRIVILEGES ON test_db.* TO 'tester'@'localhost';
FLUSH PRIVILEGES;
3. build.gradle 설정
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
//mysql 연동
implementation 'mysql:mysql-connector-java:8.0.32'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
가운데 mysql 연동 부분을 추가해 주자.
4. application.properties 설정
# MySQL 설정
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# DB Source URL 설정
# 예시) spring.datasource.url=jdbc:mysql://localhost:3306/test_db?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul
spring.datasource.url=jdbc:mysql://localhost:3306/test_db?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul&allowPublicKeyRetrieval=true
# DB 사용자 이름 설정
# 예시) spring.datasource.username=root
spring.datasource.username=tester
# DB 사용자이름에 대한 암호 설정
# 예시) spring.datasource.password=root
spring.datasource.password=test
# true 설정 시, JPA 쿼리문 확인 가능
spring.jpa.show-sql=true
# DDL(create, alter, drop) 정의 시, DB의 고유 기능을 사용할 수 있음.
spring.jpa.hibernate.ddl-auto=update
# JPA의 구현체인 Hibernate가 동작하면서, 발생한 SQL의 가독성을 높여줌.
spring.jpa.properties.hibernate.format_sql=true
Mysql 8.x.x버전부터 보안적인 이유로 useSSL=false & allowPublicKeyRetrieval=true
를 추가해 줘야 한다.
+추가
application.properties는 한글이 깨진다!!
file encodings에 체크박스 선택해주자
5. 인텔리제이 데이터베이스 연동
오른쪽 database 열기 -> + 버튼 누르기 -> Data source -> MySql 클릭
만약 팝업에 download missing driver 경고문이 있다면 다운로드해주자
application 실행 시 오류 없이 톰캣 실행되는 모습!!!!!!!!!!!
chatgpt 고맙다!!
'Spring' 카테고리의 다른 글
스프링부트 3.0.0부터 Repository를 상속받는 PagingAndSortingRepository (2) | 2023.06.15 |
---|---|
Crud 구현 중에 나타난 오류 고치기 (1) | 2023.05.24 |
Cannot parse "TIMESTAMP" constant 에러 (0) | 2023.05.23 |
스프링 REST Docs .snippet 확장자 해결 (3) | 2023.04.25 |
서버 포트 중복 해결법 (2) | 2023.03.19 |