• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

data.sql 자동 저장이 되지 않습니다

22.11.28 01:52 작성 조회수 227

0

자동 저장이 되지 않아 계속 수동으로 INSERT를 해주었는데요.

수동으로 잘 수행이 됐으니 INSERT 문에는 문제가 없을 것 같고(세미콜론도 넣었습니다.),

yml 파일의 설정이 뭔가 잘못된 걸까요?

의심가는 부분이 있으실지요?

스프링부트 버전은 2.5.5입니다.

H2도 mem.testdb가 잘 되지 않아 이렇게 저렇게 해보다가 설정파일은 다음과 같이 되었습니다.

spring:
  application:
    name: catalog-service
  messages:
    basename: messages
  # JPA
  jpa:
    hibernate:
      ddl-auto: create-drop
    show-sql: true
    generate-ddl: true
    defer-datasource-initialization: true
#  h2:
#    console:
#      enabled: true
#      settings:
#        web-allow-others: true
#      path: /h2-console
  datasource:
#    url: jdbc:h2:tcp://localhost:8082/~/testdb
    url: jdbc:h2:~/testdb
    username: sa
    password:
    driver-class-name: org.h2.Driver

답변 1

답변을 작성해보세요.

0

Architect님의 프로필

Architect

질문자

2022.11.28

자문자답입니다.

인메모리와 아닌 경우를 다르게 취급할 거라고는 상상도 못했네요.

https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-initialization

By default, SQL database initialization is only performed when using an embedded in-memory database. To always initialize an SQL database, irrespective of its type, set spring.sql.init.mode to always. Similarly, to disable initialization, set spring.sql.init.mode to never.