导入H2 SQL脚本时不会运行Spring批处理
我正在尝试运行Spring批处理应用程序来创建批处理作业 我的导入H2 SQL脚本时不会运行Spring批处理,spring,spring-boot,spring-batch,classpath,Spring,Spring Boot,Spring Batch,Classpath,我正在尝试运行Spring批处理应用程序来创建批处理作业 我的application.properties如下所示: spring.datasource.driver-class-name=org.h2.Driver spring.datasource.url=jdbc:h2:mem:localhost;DB_CLOSE_ON_EXIT=FALSE spring.datasource.username=admin spring.datasource.password=p@ssw0rd sprin
application.properties
如下所示:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:localhost;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=admin
spring.datasource.password=p@ssw0rd
spring.datasource.schema=schema-hsqldb.sql
Caused by: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException: Property spring.datasource.schema with value 'class path resource [schema-hsqldb.sql]' is invalid: The specified resource does not exist.
我得到的错误如下所示:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:localhost;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=admin
spring.datasource.password=p@ssw0rd
spring.datasource.schema=schema-hsqldb.sql
Caused by: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException: Property spring.datasource.schema with value 'class path resource [schema-hsqldb.sql]' is invalid: The specified resource does not exist.
据我所知,模式hsqldb.sql
存在于classpath/org/springframework/batch/core/schema hsqldb.sql
中
当我注释掉
Spring.datasource.schema=schema hsqldb.sql
时,Spring启动应用程序可以工作。我必须手动导入SQL脚本吗?如果是这样的话,我该怎么做?您的问题是,您正在使用HSQL模式的H2驱动程序。H2和HSQL是不同的产品。您还需要使用H2的模式:
spring.datasource.schema=/org/springframework/batch/core/schema-h2.sql
也就是说,您实际上不需要使用Spring Boot为嵌入式数据库配置数据源,数据源将自动配置。以下是参考文件部分的摘录:
SpringBoot可以自动配置嵌入式H2、HSQL和Derby数据库。您不需要提供任何连接URL。您只需要将生成依赖项包含到要使用的嵌入式数据库中