JPA, h2 / Table not found / spring.jpa.defer-datasource...

JPA, h2 / Table not found / spring.jpa.defer-datasource...

반응형

Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]:

Invocation of init method failed;nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: ~~

data.sql 에 임시 데이터를 넣어 놓고 서버를 실행시켰는데 처음보는 에러를 만났다.

table을 찾을 수 없다는 에러였다.

해당 테이블과 관련된 엔티티는 아래와 같다.

스프링부트 2.5 버전의 릴리스 노트에는 다음과 같이 설명이 되어있습니다.

따라서 위 오류는 Hibernate가 초기화되기 전에 data.sql이 먼저 실행되어서 발생하는 오류입니다.

해결 방법으로 application 설정파일에 spring.jpa.defer-datasource-initialization: true로 설정해주면 됩니다.

위와 같이 설정하고 애플리케이션을 실행하면 정상적으로 실행이 됩니다.

반응형

from http://ljg960730.tistory.com/175 by ccl(A) rewrite - 2021-12-27 00:01:25