我想用数据库创建一个Java文件。
运行Maven构建是可行的,但是一旦我将任何内容添加到 application.properties ,它就会失败。
这是我要添加到 application.properties
的内容spring.datasource.url=jdbc:sqlite:defaultdb.db
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLiteDialect
spring.jpa.hibernate.ddl-auto update
编辑:
这是错误:
-------------------------------------------------------------------------------
Test set: com.javabackendfinal.JavaBackendFinalApplicationTests
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.088 s <<< FAILURE! - in com.javabackendfinal.JavaBackendFinalApplicationTests
contextLoads(com.javabackendfinal.JavaBackendFinalApplicationTests) Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: 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
Caused by: 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
Caused by: 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
Caused by: java.lang.IllegalStateException: Cannot load driver class: org.sqlite.JDBC
答案 0 :(得分:0)
在您的pom.xml文件中添加此依赖项。它应该摆脱这个错误。 Caused by: java.lang.IllegalStateException: Cannot load driver class: org.sqlite.JDBC
这表明它无法在类路径中找到所需的类文件。
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.27.2.1</version>
</dependency>