我知道以前有人问过类似的问题,也有人回答过。但是,我已经尝试了以前答案中的解决方案,但他们没有工作。我已经尽可能的尝试了,希望有人能给我的问题提供一些帮助。
使用Apache Derby作为嵌入式数据库的春季启动错误。
还有很多来自网络的信息。但说真的,我还没有找到解决我所面临的问题的方法。
这是我的代码。
应用程序.属性
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.apache.derby derbyclient 10.15.2.0 runtime。
https:/github.commanikandarajpractice-codetreemasterjavaspring-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 APIs获得的CSV内容上运行一些查询。
我想,看来你的classpath中缺少jdbc驱动。
Mani,请在你的Application类中添加以下注解。
@EnableAutoConfiguration(exclude = { //
DataSourceAutoConfiguration.class, //
DataSourceTransactionManagerAutoConfiguration.class, //
HibernateJpaAutoConfiguration.class }
)
同时从您的pom.xml中删除以下版本。
<version>2.7.0</version>