簡體   English   中英

Spring 引導嵌入式 Apache 德比

[英]Spring Boot Embedded Apache Derby

我知道以前有人問過並回答過類似的問題。 但是我已經嘗試了以前答案中的解決方案,但它們沒有奏效。 我已經盡可能多地嘗試了,希望有人能對我面臨的問題有所了解。

在 Spring 引導應用程序中配置嵌入式 Derby

Spring-boot 錯誤使用 Apache Derby 作為嵌入式數據庫

Spring 引導非嵌入式 Derby 數據庫?

web 的更多內容。 但說真的,我還沒有看到我面臨的問題的解決方案。

這是我的代碼,

應用程序屬性

spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource
spring.datasource.url=jdbc:derby:memory:mydb;create=true
spring.datasource.driver-class-name=org.apache.derby.jdbc.EmbeddedDriver

ApacheDerbyExample.java

package com.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.boot.CommandLineRunner;

@ComponentScan("com.app")
@SpringBootApplication
public class ApacheDerbyExample implements CommandLineRunner {

    public static void main(String[] args) {
        System.out.println("STARTING THE APPLICATION");
        SpringApplication.run(ApacheDerbyExample.class, args);
        System.out.println("APPLICATION FINISHED");
    }

    @Override
    public void run(String... args) {
        System.out.println("EXECUTING : command line runner");
        //org.apache.derby.jdbc.ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
        //ds.setDatabaseName("mydb");
    }
}

從我的 pom.xml, org.apache.derby derby 10.15.2.0 runtime org.ZB6EFD606D118D0F62066E31419FF004CCZ.der2.

https://github.com/manikandaraj/practice-code/tree/master/java/spring-boot-apache-derby-embedded

我正在使用構建項目,

mvn clean package

當我跑步時,

java -jar -Dspring.config.location=config/spring-conf/application.properties target/derby-101-0.0.1-SNAPSHOT.jar

但我收到以下錯誤,

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-05-31 02:15:43.402 ERROR 8733 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Dbcp2.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.commons.dbcp2.BasicDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.apache.derby.jdbc.EmbeddedDriver
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]

我只是想在我的應用程序中使用 Apache Derby Embedded Database 並使用 Maven 中定義的依賴項,我不知道為什么我仍然收到錯誤。

我希望能夠使用嵌入式池數據源(Derby)並對從 REST API 獲得的 CSV 內容運行一些查詢。

我認為,看起來您的類路徑中缺少 jdbc 驅動程序。

Mani,請在您的應用程序 class 中添加以下注釋

@EnableAutoConfiguration(exclude = { //
    DataSourceAutoConfiguration.class, //
    DataSourceTransactionManagerAutoConfiguration.class, //
    HibernateJpaAutoConfiguration.class }

)

還要從您的 pom.xml 中刪除以下版本。

<version>2.7.0</version>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM