如何使内存数据库中的 H2 工作而不必在 springboot 中填充 data.sql 文件

how to make H2 in memory database work without having to populate the data.sql file in springboot

这可能是一个非常简单的问题,但我已经尝试搜索或 google 我怎样才能让它与空的 data.sql 文件一起工作并且无法真正找到答案,当你启动你的 springboot 时应用程序并且您正在使用 h2 数据库,除非您填充文件,否则它总是会失败,是否有办法让它忽略文件为空的事实并仍然能够拥有 h2 数据库? 以下是如果您将其设置为空时出现的错误:

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.UncategorizedScriptException: Failed to execute database script from resource [URL ["pathTo"/data.sql]]; nested exception is java.lang.IllegalArgumentException: 'script' must not be null or empty

我的应用程序属性:

spring.datasource.url=jdbc:h2:mem:citizenDB
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.defer-datasource-initialization=true
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false

尝试按照https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-initialization.using-basic-sql-scripts

设置属性spring.sql.init.mode=never(application.yml或系统环境变量)