Spring批处理CSV文件到MongoDB:配置数据源失败:未指定"url"属性,无法配置嵌入式数据源

oiopk7p5  于 2023-03-05  发布在  Spring
关注(0)|答案(1)|浏览(199)

我正在运行一个批处理示例,它从CSVFile读取数据并将其写入MongoDB。Spring Data MongoDB、Spring Batch starter与下面的详细信息一起添加。

    • 应用程序。属性:**
#Spring batch configuration
spring.batch.job.enabled=false
spring.batch.jdbc.initialize-schema=always

#Mongodb configuration
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=ntspbms715db
spring.data.mongodb.username=testuser
spring.data.mongodb.password=testuser

我遇到了下面的错误,可以通过在主类中添加@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})来修复。
现在有人能解释一下为什么我会遇到这个问题,以及上面的修复是如何解决这个错误的吗?

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

在主类中添加@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})可修复报告的问题。

zd287kbt

zd287kbt1#

由于您使用的是带有Sping Boot 的Spring Batch,您需要在应用程序上下文中定义一个数据源bean,这在本文的文档中有所提及,从Spring Batch v5开始,即使没有Spring Boot,也是如此。
此外,以下属性spring.batch.jdbc.initialize-schema=always指示Sping Boot 使用Batch表初始化JDBC数据源,但无法找到该表。

相关问题