Contents
해결insert into user_tb(username, password, email, created_at) values('ssar', '1234', 'ssar@nate.com', now()); insert into user_tb(username, password, email, created_at) values('cos', '1234', 'cos@nate.com', now());
data.sql 에 쿼리문을 작성한 후 서버를 실행하면 다음과 같은 오류가 뜬다.
org.springframework.beans.factory.BeanCreationException: 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: Failed to execute SQL script statement #1 of class path resource [db/data.sql]: insert into user_tb(username, password, email, created_at) values('ssar', '1234', 'ssar@nate.com', now()); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USER_TB" not found (this database is empty); SQL statement:
Table "USER_TB" not found
테이블이 생성되기 전보다 insert 문이 실행되어서 오류가 발생한다.
해결
defer-datasource-initialization: true
추가Share article