java - Spring Boot 嵌入式 Apache Derby
问题描述
我知道以前有人问过并回答过类似的问题。但是我已经尝试了以前答案中的解决方案,但它们没有奏效。我已经尽可能多地尝试了,希望有人能对我面临的问题有所了解。
在 Spring Boot 应用程序中配置嵌入式 Derby
使用 Apache Derby 作为嵌入式数据库的 Spring-boot 错误
还有更多来自网络。但说真的,我还没有看到我面临的问题的解决方案。
这是我的代码,
应用程序属性
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 derbyclient 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 中定义的依赖项,我不知道为什么我仍然会收到错误消息。
我希望能够使用 Embedded Pooled Data Source(Derby) 并对从 REST API 获得的 CSV 内容运行一些查询。
解决方案
我认为,看起来您的类路径中缺少 jdbc 驱动程序。
推荐阅读
- sql - Impala - 检查字符串是否为数字
- linkedin - Linkedin URL 预览不使用 javascript
- javascript - Javascript - 是否可以使用 dev.console 追溯 Javascript 变量值的来源?
- automation - 如何自动化 ETL 作业部署和运行?
- python - 使用 boto 时,长期运行的客户端对象是否安全?
- nosql - FoundationDB 身份验证
- python - numpy条件列表成员资格元素明智
- r - 我可以使用 mutate() 来模拟我将从 summarise() 与 dplyr 连接的值吗?
- swift - 在 Swift 中使用 AVAsynchronousKeyValueLoading
- swift - 为什么我们的 URLSession 对象是变量而不是常量