java - Spring Boot 嵌入式 Apache Derby

标签 java spring-boot derby

我知道之前已经提出过类似的问题并得到了回答。但我已经尝试了之前答案中的解决方案,但它们没有成功。我已经尽力尝试,希望有人能够解决我面临的问题。

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/

相关文章:

java - 用于从时间戳到标准日期格式的日期转换的Unix命令?

javascript - 即使预检响应成功,访问仍被 CORS 策略阻止 存在 'Access-Control-Allow-Origin' 通配符

java - 将数据插入DB ERROR: 'VARCHAR'类型的列不能保存 'INTEGER'类型的值

java - 优先级队列并集、交集、差异编译但不返回输出

java - 在 Java 1.5 项目中使用 Jmockit 时出现 UnsupportedClassVersionError

java - 在构造函数中初始化字段值与在字段声明中初始化字段值

spring-boot - Cors 过滤器不适用于 Spring Boot

java - 如何将每个请求存储在同一个文件中

java - Jetty + Derby 未找到合适的司机

java - Apache Derby [Hibernate 框架] 看不到创建的表。 [Java EE + JSP]