강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

황준오님의 프로필 이미지
황준오

작성한 질문수

스프링 부트 개념과 활용

스프링 데이터 7부: 데이터베이스 초기화

spring.datasource.initialization-mode=always 관련 질문드립니다.

작성

·

416

1

안녕하세요.

schema.sql 부분에서 따라 하다가

강의에서처럼 테스트 코드를 실행시키지 않고

appllication.class 를 실행시키가다 계속 에러를 띄웠습니다 ㅠ

application.class를 실행시킬 때 h2 DB를 사용할 경우에는 문제 없는데,

postgreSQL을 사용할 경우에는 schema.sql이 반영이 안됬습니다.

검색해본 결과

spring.datasource.initialization-mode=always

를 properties에 추가해주어야 적용이 되던데,

이는 개발자가 실수로 프로덕션용 db를 초기화 할까봐 우려해서

일부러 적용이 안되게 한 것 인지 궁금합니다

답변 1

0

백기선님의 프로필 이미지
백기선
지식공유자

네 추측하신게 맞습니다. schema.sql로 데이터 베이스 스키마 생성하는 기능을 기본적으로 embedded DB만 지원하구요. 다른 DB들은 위에 쓰신 설정을 해줘야 가능합니다.

아래는 레퍼런스 본문입니다.

[Note]

Spring Boot automatically creates the schema of an embedded DataSource. This behaviour can be customized by using the spring.datasource.initialization-mode property. For instance, if you want to always initialize the DataSource regardless of its type:

spring.datasource.initialization-mode=always

좋은 질문 감사합니다.

황준오님의 프로필 이미지
황준오

작성한 질문수

질문하기