如何配置Progress Database的数据源/驱动程序管理器?

huangapple go评论75阅读模式
英文:

How to configure Datasource/Driver Manager with Progress Database?

问题

我想在我的Spring Boot应用程序中配置一个Progress DB 10.2B的连接。

我尝试阅读了Progress的文档,但是没有找到适合我场景的内容。这是我找到的文档链接:[Progress文档][1]

在OpenEdge解决方案中,我提供了"openedge.jar"驱动程序文件。

但是,我不知道如何在Spring Boot中使用Maven配置不同的DriverClass。我应该做什么?我是否应该创建一个名为"DatasourceConfig.java"的新类,并放置一个返回应用程序应使用的Progress连接的方法?

我尝试了类似这样的代码(非常初学者),但我不知道如何使其与我的实体和存储库一起工作:

```java
public class DatasourceConfig {

    public DatasourceConfig() throws ClassNotFoundException {
        Class.forName("com.ddtek.jdbc.openedge.OpenEdgeDriver");
    }

    @Bean
    Connection dataSource() throws SQLException {
        String url = "jdbc:datadirect:openedge://localhost:5522;databaseName=farms;user=xul;password=Xul$445";
        Connection con = DriverManager.getConnection(url);
        return con;
    }
}

我还尝试了在"application.properties"中配置:

spring.datasource.driver-class-name=com.ddtek.jdbc.openedge.OpenEdgeDriver
spring.datasource.url=jdbc:datadirect:openedge://localhost:5522;databaseName=farms

并在我的pom.xml文件中使用了以下依赖项,这些依赖项是在https://stackoverflow.com/a/36602256/7712038上创建的:

<dependency>
    <groupId>com.ddtek.jdbc.openedge</groupId>
    <artifactId>OpenEdgeDriver</artifactId>
    <version>10.2</version>
</dependency>

但仍然会出现以下异常:

org.springframework.beans.factory.UnsatisfiedDependencyException: 在类路径资源 [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class] 中定义的名为'inMemoryDatabaseShutdownExecutor'的bean创建失败:通过方法'inMemoryDatabaseShutdownExecutor'表达的不满足的依赖关系,该方法的参数0;嵌套异常是org.springframework.beans.factory.BeanCreationException: 通过工厂方法创建的bean名为'dataSource'在类路径资源 [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] 中定义失败:通过工厂方法'数据源'抛出异常;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource'抛出异常;嵌套异常是java.lang.IllegalStateException:无法加载驱动程序类:com.ddtek.jdbc.openedge.OpenEdgeDriver
    ...

(以下为异常的继续部分,不再重复)


<details>
<summary>英文:</summary>

I would like to configure an Progress DB 10.2B connection in my Spring Boot application.

I tried to read the Progress documentation but I didn&#39;t find anything that fits my scenario. This is the doc link that I&#39;ve found: [Progress Documentation][1]

I have &quot;openedge.jar&quot; driver file provided in the OpenEdge solution.

But, I don&#39;t know how to configure a different DriverClass in Spring Boot with Maven in &quot;pom.xml&quot;. 

What should I do? Should I create a new class with the name &quot;DatasourceConfig.java&quot; and put a method that would return the Progress connection that should be used by the application?

I tried something like this (very newbie) but I don&#39;t know how to make it work with my entities and repositories:

public class DatasourceConfig {

public DatasourceConfig() throws ClassNotFoundException {
    Class.forName(&quot;com.ddtek.jdbc.openedge.OpenEdgeDriver&quot;);
}

@Bean
Connection dataSource() throws SQLException {

    String url = &quot;jdbc:datadirect:openedge://localhost:5522;databaseName=farms;user=xul;password=Xul$445&quot;;
    Connection con = DriverManager.getConnection(url);
    return con;

}

}


I also tried by the &quot;application.properties&quot;:

    spring.datasource.driver-class-name=com.ddtek.jdbc.openedge.OpenEdgeDriver
    spring.datasource.url=jdbc:datadirect:openedge://localhost:5522;databaseName=farms 

With the following dependency in my pom.xml file, created with the help of https://stackoverflow.com/a/36602256/7712038:

    &lt;dependency&gt;
			&lt;groupId&gt;com.ddtek.jdbc.openedge&lt;/groupId&gt;
			&lt;artifactId&gt;OpenEdgeDriver&lt;/artifactId&gt;
			&lt;version&gt;10.2&lt;/version&gt;
		&lt;/dependency&gt;

It stills gives me the following exception:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' 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: com.ddtek.jdbc.openedge.OpenEdgeDriver
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:538) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:311) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at com.luxarvum.interfaces_datasul.InterfacesDatasulApplication.main(InterfacesDatasulApplication.java:10) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.3.4.RELEASE.jar:2.3.4.RELEASE]
Caused by: 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: com.ddtek.jdbc.openedge.OpenEdgeDriver
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:635) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
... 27 common frames omitted
Caused by: 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: com.ddtek.jdbc.openedge.OpenEdgeDriver
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
... 41 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot load driver class: com.ddtek.jdbc.openedge.OpenEdgeDriver
at org.springframework.util.Assert.state(Assert.java:97) ~[spring-core-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:223) ~[spring-boot-autoconfigure-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:175) ~[spring-boot-autoconfigure-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43) ~[spring-boot-autoconfigure-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:85) ~[spring-boot-autoconfigure-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
... 42 common frames omitted


  [1]: https://knowledgebase.progress.com/articles/Article/21246

</details>


# 答案1
**得分**: 2

一般来说,有效/已知的驱动程序 jar 文件通常会被官方打包在官方的 Maven 仓库下,因此获取所有传递依赖项会更加容易。在你的情况下(根据你分享的文档),似乎需要多个 jar 文件处于正确的位置,才能初始化 Spring Boot 应用程序。

一些选项:

1. 正如你所说,尝试将所有所需的 jar 包安装为自定义/本地包,可以安装到本地机器上或者放入一个私有远程仓库中,然后在 pom.xml 文件中使用相同名称创建依赖引用。验证最终的包是否包含了所有所需的库(外部/内部取决于你如何导出最终的可执行文件)。

2. 使用 Maven 系统依赖,并且将它们仅作为单独的 jar 引用(这不是一个真正推荐的解决方案)。一个类似的问题[在这里](https://stackoverflow.com/questions/30347310/adding-a-system-dependency-to-maven)。

3. 手动将所有的 jar 包复制到 Spring Boot 的 lib 目录下(!)(再次强调不推荐,仅用于验证)。

<details>
<summary>英文:</summary>

Generally the - valid/known - driver jar files are officially packaged under an official Maven repository, so fetching all transient dependencies would be much easier. In your case (from the documentation you shared as well), it seems that there&#39;s more than one jar needed to be in place, while the Spring Boot application gets initialized.

Some options: 

1. As you said, try to install all required jars as custom/local packages, either to your local machine or into a private remote repository, and then create the dependency references with the same names inside your pom.xml. Verify that the final package contains all required libraries (externally/internally depends on how you are exporting the final executable).

2. Use Maven system dependencies, and just refer to them as single jars (not really recommended as a concrete solution). A similar question [here](https://stackoverflow.com/questions/30347310/adding-a-system-dependency-to-maven)

3. Manually copy all jars inside the Spring Boot&#39;s lib directory (!) (Again not recommended, just for the proof)

</details>



# 答案2
**得分**: 1

```xml
Você precisa simular o arquivo JAR "openedge.jar" para adicioná-lo ao repositório ".m2", da seguinte maneira:

    mvn install:install-file
       -Dfile=src\main\resources\driver\openedge.jar
       -DgroupId=ddtek
       -DartifactId=com.ddtek
       -Dversion=1.0
       -Dpackaging=com.ddtek
       -DgeneratePom=true

Após realizar esse procedimento, será gerada uma dependência no repositório M2. Em seguida, adicione da seguinte forma ao seu arquivo "pom.xml" para que o driver seja reconhecido:

    <!-- Dependência JDBC, execute o script para simular o repositório na pasta M2 -->
    <dependency>
         <groupId>com.ddtek</groupId>
         <artifactId>ddtek</artifactId>
    	 <version>1.0</version>
    </dependency>
英文:

Você precisar simular a jar "openedge.jar" para adicionar no repository do ".m2", da seguinte forma:

mvn install:install-file
   -Dfile=src\main\resources\driver\openedge.jar
   -DgroupId=ddtek
   -DartifactId=com.ddtek
   -Dversion=1.0
   -Dpackaging=com.ddtek
   -DgeneratePom=true

Após fazer isso vai gerar uma dependência no repository m2, então adiciona da seguinte forma, em seu arquivo "pom.xml" então reconhecerá o driver

&lt;!-- JDBC dependencia, rodar escript para simular repository na pasta m2 --&gt;
&lt;dependency&gt;
     &lt;groupId&gt;com.ddtek&lt;/groupId&gt;
     &lt;artifactId&gt;ddtek&lt;/artifactId&gt;
	 &lt;version&gt;1.0&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年10月2日 02:42:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64161441.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定