Spring_MySQL 연결_gradle

2023. 3. 22. 22:48Spring

728x90

1. 의존성 찾기

https://mvnrepository.com/artifact/com.mysql/mysql-connector-j/8.0.32

2. build.gradle에 의존성 추가

3. application.yml

spring:
  # MySQL
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: ${mysql.url}
    username: ${mysql.username}
    password: ${mysql.password}

4. ENV 파일 작성

# Mysql
mysql.url=jdbc:mysql://url:포트/DB이름?serverTimezone=UTC&characterEncoding=UTF-8
mysql.username=아이디
mysql.password=비밀번호

5. Spring Env 설정

https://lazybones1.tistory.com/12

 

Spring_env 파일 설정

1. .gitignore 설정 ### env ### !**/properties/ env.properties 2. Spring에서 설정 @Configuration @PropertySources(@PropertySource("classpath:properties/env.properties")) //env.propoerties 파일 소스 등록 public class EnvConfig { } 3. env.properti

lazybones1.tistory.com

 

'Spring' 카테고리의 다른 글

GenerationType  (0) 2023.03.31
Spring_Entity, DTO, VO  (0) 2023.03.22
Spring_tinyLog  (0) 2023.03.09
Spring_JPA_페이지네이션  (0) 2022.12.28
Spring_env 파일 설정  (0) 2022.12.28