반응형

resources 폴더 아래의 application.properties 파일을 열어서 하기의 내용을 추가한다.

 

pring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.url=jdbc:mariadb://localhost:3306/dbname #db connection url
spring.datasource.username=dbuser #username
spring.datasource.password=pswd #password

#Runtime 콘솔 화면에 SQL 쿼리문을 나타낸다.
spring.jpa.show-sql=true
# Runtime 콘솔 화면에 나타나는 SQL 쿼리문을 깔끔하게 정렬해서 나타낸다.
spring.jpa.properties.hibernate.format_sql=true
#show sql - jpa가 생성하는 쿼리를 콘솔로 출력
spring.jpa.properties.hibernate.show_sql=true
#use sql comment
spring.jpa.properties.hibernate.use_sql_comments=true
# JPA 사용 시 초기화 및 생성 전략 설정 (create, update, create-drop, validate)
# 보통 라이브 환경에서는 update, validate를 사용하고 개발시에는 create, create-drop을 사용합니다.
# create : 매번 테이블 생성을 새로 시도합니다.
# update : 변경이 필요한 경우는 alter 명령이 실행되고, 테이블이 없는 경우 create 명령이 실행됩니다.
# create-drop : create와 동일하며 SessionFactory가 내려가면 테이블을 drop 시킵니다.
# validate : update와 동일하게 Object를 검사하지만 스키마는 건드리지 않고 데이터만 변경합니다. 스키마 구조가 다르면 에러를 발생시킵니다.
# none 아무것도 안함.
# @Entity 컴포넌트를 스캔하여, 서버 실행 시 Table "자동 생성" 및 서버 종료 시 Table "자동 삭제"한다.
spring.jpa.hibernate.ddl-auto=update
spring.jpa.open-in-view=true

# spring.datasource.initialization-mode=always 바뀜
# 서버실행시 자동 실행 src/main/resources/data.sql
spring.sql.init.mode=always
spring.jpa.defer-datasource-initialization=true

 

반응형

+ Recent posts