gpt4 book ai didi

java - Spring Boot 嵌入式 Apache Derby

转载 作者:行者123 更新时间:2023-12-04 09:45:57 25 4
gpt4 key购买 nike

我知道之前有人问过并回答过类似的问题。但是我已经尝试了之前答案中的解决方案,但它们没有奏效。我已经尽可能多地尝试过,希望有人能对我面临的问题有所了解。

Configuring embedded Derby in Spring Boot app

Spring-boot error using Apache Derby as embedded database

Spring Boot non-embedded Derby database?

还有更多来自网络的内容。但说真的,我还没有看到我面临的问题的解决方案。

这是我的代码,

应用程序属性

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
运行


org.apache.derby
Derby 客户端
10.15.2.0
运行


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 嵌入式数据库,并使用 Maven 中定义的依赖项,我不知道为什么我仍然收到错误。

我希望能够使用嵌入式池数据源(Derby)并对我从 REST API 获得的 CSV 内容运行一些查询。

最佳答案

我认为,您的类路径中似乎缺少 jdbc 驱动程序。

关于java - Spring Boot 嵌入式 Apache Derby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62108654/

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