不使用 spring 批处理 + spring boot + sql server 应用程序运行 DDL 脚本 [英] Not running DDL scripts with spring batch + spring boot + sql server application

查看:22
本文介绍了不使用 spring 批处理 + spring boot + sql server 应用程序运行 DDL 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My project has this requirement where user uploads a CSV file which has to be pushed to sql server database. I am following the below basic example to load CSV file into a sql sever database. https://github.com/michaelcgood/Spring-Batch-CSV-Example runninng this repo by making change of datasource, here we using sql server instead of in-memory db.

这是对 POM 文件的补充:

here is the addition to POM file:

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

对applications.properties 文件的添加

additions to applications.properties file

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

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

Below is the error generated while running the code base, we could not found exact root cause we tried the multiple approaches as mentioned in the google but no luck, while running this spring batch+spring boot 2.0.4 application we are facing the below errors:

    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 批处理配置,所以不知道我们如何定义默认表架构和所有.

1.We are using the spring starter project for creating spring batch configuration so not aware how we could define the default table schema and all.

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

2.maybe we don't have access and/or you need to define the schema. http://forum.spring.io/forum/spring-projects/batch/63771-badsqlgrammarexception-running-commandlinejobrunner

3.不确定为什么错误是说无效的对象名称BATCH_JOB_INSTANCE"而不是对象不存在?为 spring 批处理应用程序创建元数据表的 sql 查询列表是什么,在运行应用程序之前手动创建它.

3.Not sure on the why error is saying Invalid object name 'BATCH_JOB_INSTANCE' instead of object doesnot exist? What are the list of sql queries to create metadate table for spring batch application, to create it manually before running application.

4.我们正在努力寻找问题的根本原因,请通过上述 github 代码库示例提出建议.任何帮助在这里将不胜感激.如果我们在这里遗漏了什么,请告诉我们.提前致谢

4.we are struggling from couple of days to find the root cause of issue, Please suggest approch by taking the above github code base sample. any help here would be appreciated. Please let us know if we missed anything here. Thanks In advance

推荐答案

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

The project you are linking to uses the in-memory hsqldb instance so Spring Boot will automatically create Spring Batch meta-data tables for you.

如果您想让示例适应您的项目并使用 sql server(未嵌入您的 JVM),Spring Boot 将创建 Spring Batch 表(除非您指示它这样做)).在这种情况下,您有两个选择:

If you want to adapt the sample to your project and use sql server (which is not embedded in your JVM), Spring Boot will not create Spring Batch tables (unless you instruct it to do so). In this case, you have two options:

  • Run the Spring Batch DDL script for sqlserver yourself against the db server you are using before running your app

或者通过在 application.properties 文件中指定以下属性来指示 Spring Boot 为您执行此操作:

Or instruct Spring Boot to do it for you by specifying the following properties in your application.properties file:

spring.batch.initialize-schema=alwaysspring.batch.schema=classpath:org/springframework/batch/core/schema-sqlserver.sql

这篇关于不使用 spring 批处理 + spring boot + sql server 应用程序运行 DDL 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆