* spring boot gradle mysql & oracle db 연동 / JPA + security 설정
버전 정보
- JavaSE-11 버전
- Oracle 18c
- MySQL 8.0.22
버전을 상당히 많이 타기 때문에,
(예를 들면 ojdbc8.jar 같은 외부 라이브러리라던가, dialect 설정 따위라던가 하는 것들)
막히는 부분은 구글링 필수!
---------------------------------------- 1. DB 연동 ----------------------------------------
Oracle
#build.gradle
runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
#application.properties
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:XE
spring.datasource.username=계정명
spring.datasource.password=qwer1234
당연히 OracleServiceXE는 켜져있어야 한다.
Mysql
#build.gradle
runtimeOnly 'mysql:mysql-connector-java'
#application.properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/DB명?serverTimezone=UTC&characterEncoding=UTF-8
spring.datasource.username=계정명
spring.datasource.password=qwer1234
당연히 MySQL은 DB명과 동일한 DB를 생성해두어야 한다.
생성 명령어 관련 (https://verycrazy.tistory.com/28?category=1025126)
MySQL + hikari CP
#application.properties
spring.datasource.hikari.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.hikari.jdbc-url=jdbc:mysql://localhost:3306/DB명?serverTimezone=UTC&characterEncoding=UTF-8
spring.datasource.hikari.username=계정명
spring.datasource.hikari.password=qwer1234
+더하여, DatabaseConfiguration.java를 설정해주어야 한다. 아니면 아래와 같은 에러를 만난다.
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
-------------------- 2. JPA + security 연동 --------------------
Oracle
#build.gradle
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
testImplementation 'org.springframework.security:spring-security-test'
#application.properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jpa.database=oracle
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
logging.level.org.hibernate=info
Mysql
#build.gradle
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
testImplementation 'org.springframework.security:spring-security-test'
#application.properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
logging.level.org.hibernate=info
JPA dialect 관련 정보:
https://verycrazy.tistory.com/85
DB 생성 관련 명령어:
https://verycrazy.tistory.com/28?category=1025126