
개인적으로 Spring Security를 활용한 인증/인가 공부를 하던 와중 어플리케이션 실행시 엔티티에 대응되는 테이블이 제대로 생성되지 않는 이슈가 발생했다.
application.yml
spring:
datasource:
url: jdbc:mysql://localhost:3390/security?serverTimezone=Asia/Seoul
username: spring_boot_study
password: my-password
driver-class-name: com.mysql.cj.jdbc.Driver
mvc:
view:
prefix: /templates/
suffix: .mustache
jpa:
properties:
hibernate:
ddl-auto: create
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
dialect: org.hibernate.dialect.MySQLDialect
show-sql: true
다른 문제가 될 만한 요소들을 전부 확인하였는데 알고 보니 ddl-auto가 잘못
설정되어 있었다. 다른 프롲젝트의 application.yml 파일을 보며 설정하며 알게된
사실인데 ddl-auto와 관련해서는 다음 두 프로퍼티를 통해 설정이 가능하다.
jpa.hibernate.ddl-autojpa.properties.hibernate.hbm2ddl.auto두 방식의 차이점은 properties를 통해 설정할 경우 hibernate의 다른 기본 속성과 함께 설정이 가능하다는 점이었다. 참고하던 강의 코드와 이전에 했던 프로젝트 코드의 application.yml 설정 방식이 달라 발생한 트러블이었다... 두 방식 모두 같은 기능을 지원한다.
jpa.hibernate.ddl-auto를 통한 설정
spring:
datasource:
url: jdbc:mysql://localhost:3390/security?serverTimezone=Asia/Seoul
username: spring_boot_study
password: my-password
driver-class-name: com.mysql.cj.jdbc.Driver
mvc:
view:
prefix: /templates/
suffix: .mustache
jpa:
hibernate:
ddl-auto: create
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
show-sql: true
jpa.properties.hibernate.hbm2ddl.auto를 통한 설정
spring:
datasource:
url: jdbc:mysql://localhost:3390/security?serverTimezone=Asia/Seoul
username: spring_boot_study
password: my-password
driver-class-name: com.mysql.cj.jdbc.Driver
mvc:
view:
prefix: /templates/
suffix: .mustache
jpa:
properties:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
dialect: org.hibernate.dialect.MySQLDialect
hbm2ddl:
auto: create
show-sql: true