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