gpt4 book ai didi

java - 如何将Oracle驱动程序依赖添加到Spring Data Flow Server?

转载 作者:行者123 更新时间:2023-12-02 00:57:10 27 4
gpt4 key购买 nike

我目前正在尝试使用 Spring Batch 的 Spring Data Flow Server。我的 application.properties 中有两个数据源。 Spring Batch 应用程序工作正常,它可以读取数据并将数据写入数据库。

但是当我尝试在 Spring Cloud Data Flow 服务器中部署 Jar 文件时,SCDF 不会从 application.properties 文件加载属性并加载默认的 h2 配置。我还尝试在启动 SCDF 时将配置作为参数传递,但我在类路径中找不到 Oracle Driver。但请记住批处理作业会工作并插入数据。我的问题是,在 SCDF 启动期间将这些数据库配置作为参数传递时,我应该将 Oracle Jdbc 驱动程序 jar (ojdbc7-1.0.0 ) 保存在哪里?或者如何添加依赖项以便 SCDF 能够看到数据库配置。下面是我传递数据库参数的方法。

java -jar spring-cloud-dataflow-server-2.4.2.BUILD-20200310.115040-7.jar
--spring.datasource.url=jdbc:oracle:thin:@mydb
--spring.datasource.username=username
--spring.datasource.password=password
--spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

我得到的异常(exception)是,

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.OracleDriver
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:617)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:605)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1242)
at org.springframework.boot.actuate.autoconfigure.health.HealthEndpointConfiguration.healthContributorRegistry(HealthEndpointConfiguration.java:78)

我在另一个SO问题中发现可以将oracle驱动程序依赖项添加到SCDF中。但他没有明确提及如何,我也没有足够的积分来添加评论。因此在这里发帖。我所指的答案的链接是,

spring-data-flow task example

I have fixed the same issue by getting SCDF source code & added oracle dependency jars and ran the command same as above. It worked. You need to make sure that you added drivers for DB in SCDF before running the above command. SCDF comes with DB related jars but if you are using oracle or some third party you need to add it manually. 

感谢任何帮助。

注意:在我的应用程序中,我扩展了 DefaultTaskConfigurer 并返回了包含 Task_Execution 和相关表的 Oracle 数据源。但这似乎没有任何作用。

最佳答案

根据Spring Cloud Data Flow reference (第 24.1.1 节),您应该在应用程序 pom 文件的 dependencies 部分添加所需数据库驱动程序的依赖项(在您的情况下为 Oracle)。

<dependencies>
...
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
...
</dependencies>

然后您必须按照此处所述构建应用程序:Building Spring Cloud Data Flow .

幸运的是,现在 Oracle 的 JDBC 驱动程序可在 Maven Central 上获得。

还检查:

Add Custom JDBC Driver to Spring Cloud Data Flow Server

SCDF Provide better docs on how to add Oracle JDBC Driver

关于java - 如何将Oracle驱动程序依赖添加到Spring Data Flow Server?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61207719/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com