Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Erro ao popular banco H2 com arquivo data.sql

Estou tentando popular o banco H2 com arquivo data.sql porem recebo um erro que não existe a tabela, ja mudei o arquivo apllication.yml para application.properties, e o erro continua.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-08 10:34:43.294 ERROR 13888 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

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 URL [file:/C:/Users/raffa/eclipse-workspace/forum-kotlin/forum/target/classes/data.sql]: insert into USUARIO(id, nome, email) values(1, 'Rafael', 'rafael@email.com'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USUARIO" not found; SQL statement:
insert into USUARIO(id, nome, email) values(1, 'Rafael', 'rafael@email.com') [42102-200]

Arquivo application.properties

spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:forum
spring.datasource.username=sa
spring.datasource.password=

# jpa
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true

# h2
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

Arquivo data.sql

insert into usuario(id, nome, email) values(1, 'Rafael', 'rafael@email.com');
1 resposta
solução!

A partir da versao 2.5.0 do Spring Boot precisa dessa linha a mais no application.properties:

spring.jpa.defer-datasource-initialization=true