我试图将我的Spring启动应用程序(Web服务)与Sqlite数据库集成,但我一开始就陷入困境。 由于documentation我指定了连接网址:
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:sqlite:test.db
并添加依赖于apprpiate lib(有和没有"范围运行时"结果是相同的):
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
(repositories...)
当我尝试运行我的应用程序时,我在控制台中看到了信息:
申请失败
说明
无法绑定&#39;&#39;&#39;&#39;到com.zaxxer.hikari.HikariDataSource:
属性:driverclassname
值:org.sqlite.JDBC
原产地:&#34; driverClassName&#34;来自财产来源&#34;来源&#34;
原因:无法为属性driver-class-name
设置值动作:
更新您的应用程序的配置
我检查过的第一件事是使用类org.sqlite.JDBC(sqlite-jdbc-3.21.0.1.jar)的lib在我的超级jar中(我用mvn clean install用skip生成它-tests flag)并且它存在(它被打包在my_app.jar \ BOOT-INF \ lib中)。即使我从命令行启动我的应用程序,我也会看到相同的错误(因此它不是错误)。
接下来,我想也许我必须手动指定驱动程序类名,所以我写道:
spring.datasource.driver-class-name=org.sqlite.JDBC
然后我看到了栈跟踪:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.sqlite.JDBC
(...)
接下来,我尝试添加另一个启动器:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
......但没有改变
我不知道如何处理这个问题。我用Google搜索配置spring-boot和sqlite,但我没有找到任何帮助。
请帮忙,我会非常感谢任何线索:)
PS:我的应用程序在MySql数据库上正常运行
PS2:我使用的是最新版本的hibernate,而且我没有使用sql方言的问题