如何将Oracle驱动程序依赖项添加到Spring Data Flow Server? [英] How to add Oracle Driver dependency to Spring Data Flow Server?

查看:84
本文介绍了如何将Oracle驱动程序依赖项添加到Spring Data Flow Server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently trying Spring Data Flow Server with Spring Batches. I have two datasources in my application.properties. And the Spring Batch application works fine and it reads and writes data into the Database.

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

But When I tried to deploy the Jar file in Spring Cloud Data Flow server, the SCDF doesn't load the properties from application.properties file and loads the default h2 config. I also tried passing the config as arguments when the starting the SCDF, but I get Oracle Driver not found in class path. But remember batch jobs work and inserts data. My question here is where I should keep the Oracle Jdbc Driver jar (ojdbc7-1.0.0 ) when passing those database config as arguments during SCDF startup? Or how to add the dependency so the SCDF would see the database config. Below is how I passed Database arguments.

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

而我得到的异常,

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中。但是他没有明确提及操作方法,因此我没有足够的意见要发表评论。因此在这里发布。而我所指的答案的链接是

I found in another SO question that oracle driver dependency could be added to SCDF. But he didn't mention clearly how, and I do not have enough points to add a comment. Hence posting here. And the link to the answer I'm referring to is,

spring-data-flow任务示例

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数据源。但这似乎无济于事。

Note: In my application I have extended the DefaultTaskConfigurer and returned the Oracle Datasource which has Task_Execution and related tables. But this seems to do nothing.

推荐答案

根据 Spring Cloud数据流参考(第24.1节)。 1),您应该在应用程序pom文件的依赖项部分中添加所需的数据库驱动程序的依赖项(在您的情况下为Oracle)。

According to Spring Cloud Data Flow reference (Section 24.1.1), you should add the dependency for the database driver required (Oracle in your case) in the dependencies section of your application's pom file.

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

然后,您必须按照以下说明构建应用程序:构建Spring Cloud数据流

Then you must build the application as described here: Building Spring Cloud Data Flow.

如今对我们来说幸运的是,可以在 Maven Central

Lucky for us nowdays Oracle's JDBC drivers are available on Maven Central

还要检查:

向Spring Cloud Data Flow Server添加自定义JDBC驱动程序

SCDF提供了有关如何添加Oracle JDBC驱动程序的更好文档

这篇关于如何将Oracle驱动程序依赖项添加到Spring Data Flow Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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