如何将 Oracle Driver 依赖项添加到 Spring Data Flow Server?
How to add Oracle Driver dependency to Spring Data Flow Server?
我目前正在尝试 Spring 数据流服务器 Spring 批次。我的 application.properties 中有两个数据源。 Spring Batch 应用程序工作正常,它可以将数据读取和写入数据库。
但是当我尝试在 Spring 云数据流服务器中部署 Jar 文件时,SCDF 不会从 application.properties 文件加载属性并加载默认的 h2 配置。我还尝试在启动 SCDF 时将配置作为参数传递,但我在 class 路径中找不到 Oracle 驱动程序。但请记住批处理作业工作并插入数据。我的问题是在 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
我得到的异常,
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[=12=](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[=12=](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。但是他没有明确提到如何,我没有足够的积分来添加评论。因此在这里张贴。我指的答案 link 是
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。
幸运的是,我们现在可以在 Maven Central
上获得 Oracle JDBC 驱动程序
同时检查:
我目前正在尝试 Spring 数据流服务器 Spring 批次。我的 application.properties 中有两个数据源。 Spring Batch 应用程序工作正常,它可以将数据读取和写入数据库。
但是当我尝试在 Spring 云数据流服务器中部署 Jar 文件时,SCDF 不会从 application.properties 文件加载属性并加载默认的 h2 配置。我还尝试在启动 SCDF 时将配置作为参数传递,但我在 class 路径中找不到 Oracle 驱动程序。但请记住批处理作业工作并插入数据。我的问题是在 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
我得到的异常,
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[=12=](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[=12=](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。但是他没有明确提到如何,我没有足够的积分来添加评论。因此在这里张贴。我指的答案 link 是
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。
幸运的是,我们现在可以在 Maven Central
上获得 Oracle JDBC 驱动程序同时检查: