没有使用spring batch + spring boot + sql server应用程序运行DDL脚本

问题描述 投票:1回答:1

我的项目有这个要求,用户上传一个必须被推送到sql server数据库的CSV文件。我按照以下基本示例将CSV文件加载到sql sever数据库中。 https://github.com/michaelcgood/Spring-Batch-CSV-Example通过更改数据源来运行此repo,这里我们使用sql server而不是内存中的db。

这是POM文件的补充:

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<</dependency>

添加到applications.properties文件

spring.datasource.url=jdbc:sqlserver://localhost;databaseName=springbootdb
spring.datasource.username=sa
spring.datasource.password=Projects@123

下面是运行代码库时产生的错误,我们找不到确切的根本原因我们尝试了谷歌中提到的多种方法但没有运气,而运行这个春季批处理+ spring boot 2.0.4应用程序我们面临以下错误:

    spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
o.s.boot.autoconfigure.jdbc.Datasource.initailizer disabled(not running DDL scripts)

at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE
 where JOB_NAME = ? order by JOB_INSTANCE_ID desc]; nested exception is java.sql.SQLServerException: Invalid object name 'BATCH_JOB_INSTANCE'.

我们假设下面的根本原因之一?

1.我们正在使用spring starter项目来创建spring批量配置,因此不知道如何定义默认表模式和所有。

2.可能我们没有访问权限和/或您需要定义架构。 http://forum.spring.io/forum/spring-projects/batch/63771-badsqlgrammarexception-running-commandlinejobrunner

3.不确定错误的原因是说无效的对象名称'BATCH_JOB_INSTANCE'而不是对象不存在?有哪些sql查询列表可以为spring批处理应用程序创建元数据表,以便在运行应用程序之前手动创建它。

4.我们几天都在苦苦寻找问题的根本原因,请通过上面的github代码基础样本建议approch。任何帮助在这里将不胜感激。如果我们在这里遗漏了什么,请告诉我们。提前致谢

spring spring-mvc spring-boot spring-data-jpa spring-batch
1个回答
1
投票

您链接到的项目使用内存中的hsqldb实例,因此Spring Boot将自动为您创建Spring Batch元数据表。

如果要将示例调整到项目并使用sql server(未嵌入JVM中),Spring Boot将不会创建Spring Batch表(除非您指示它执行此操作)。在这种情况下,您有两种选择:

  • 在运行应用程序之前,请针对您使用的数据库服务器自行运行Spring Batch DDL script for sqlserver
  • 或者通过在application.properties文件中指定以下属性,指示Spring Boot为您执行此操作: spring.batch.initialize-schema=always spring.batch.schema=classpath:org/springframework/batch/core/schema-sqlserver.sql
© www.soinside.com 2019 - 2024. All rights reserved.