Spring 启动错误“尝试调用不存在的方法”

问题描述 投票:0回答:1

我将项目的数据库从 H2 更改为 SQLite,出现了这些错误。我该如何修复它们?

描述:

尝试调用不存在的方法。尝试是从以下位置进行的:

org.sqlite.hibernate.dialect.SQLiteDialect.<init>(SQLiteDialect.java:58)

以下方法不存在:

'void org.sqlite.hibernate.dialect.SQLiteDialect.registerColumnType(int, java.lang.String)'

调用方法的类 org.sqlite.hibernate.dialect.SQLiteDialect 是从以下位置加载的:

jar:file:/C:/Users/hbyeon/.m2/repository/com/github/gwenn/sqlite-dialect/0.1.4/sqlite-dialect-0.1.4.jar!/org/sqlite/hibernate/dialect/SQLiteDialect.class

被调用方法的类 org.sqlite.hibernate.dialect.SQLiteDialect 可从以下位置获取:

jar:file:/C:/Users/hbyeon/.m2/repository/com/github/gwenn/sqlite-dialect/0.1.4/sqlite-dialect-0.1.4.jar!/org/sqlite/hibernate/dialect/SQLiteDialect.class

被调用方法的类层次结构是从以下位置加载的:

org.sqlite.hibernate.dialect.SQLiteDialect: file:/C:/Users/hbyeon/.m2/repository/com/github/gwenn/sqlite-dialect/0.1.4/sqlite-dialect-0.1.4.jar
org.hibernate.dialect.Dialect: file:/C:/Users/hbyeon/.m2/repository/org/hibernate/orm/hibernate-core/6.5.3.Final/hibernate-core-6.5.3.Final.jar

行动:

更正应用程序的类路径,使其包含单个兼容版本的 org.sqlite.hibernate.dialect.SQLiteDialect

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>3.3.5</version>
       <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>task</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>task</name>
    <description>Demo project for Spring Boot</description>
    <url/>
    <licenses>
       <license/>
    </licenses>
    <developers>
       <developer/>
    </developers>
    <scm>
       <connection/>
       <developerConnection/>
       <tag/>
       <url/>
    </scm>
    <properties>
       <java.version>23</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</artifactId>
       </dependency>

       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-devtools</artifactId>
          <scope>runtime</scope>
          <optional>true</optional>
       </dependency>

       <dependency>
          <groupId>org.xerial</groupId>
          <artifactId>sqlite-jdbc</artifactId>
       </dependency>

       <dependency>
          <groupId>com.github.gwenn</groupId>
          <artifactId>sqlite-dialect</artifactId>
          <version>0.1.4</version>
       </dependency>

       <dependency>
          <groupId>org.mockito</groupId>
          <artifactId>mockito-core</artifactId>
          <scope>test</scope>
       </dependency>

       <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <optional>true</optional>
       </dependency>
       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>
       </dependency>
    </dependencies>

    <build>
       <plugins>
          <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <configuration>
                <excludes>
                   <exclude>
                      <groupId>org.projectlombok</groupId>
                      <artifactId>lombok</artifactId>
                   </exclude>
                </excludes>
             </configuration>
          </plugin>
       </plugins>
    </build>

</project>

这是我的应用程序属性

spring.application.name=task

spring.datasource.url=jdbc:sqlite:mydatabase.db
spring.datasource.driver-class-name=org.sqlite.JDBC

spring.jpa.database-platform=org.hibernate.dialect.SQLiteDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

以前,我遇到了一个错误,提示“无法解析名称 org.hibernate.dialect.SQLiteDialect”,我通过将 sqlite-dialect 依赖项添加到我的 pom.xml 文件来解决该问题。然而,现在这些新错误又出现了。

出现此错误,我尝试删除 c:\users\ 中的 .m2 文件夹并关闭项目并再次打开,但不起作用。

java spring-boot sqlite maven
1个回答
0
投票

这是 Hibernate 的 SQLite 方言的正确设置:

<dependency>
    <groupId>org.hibernate.orm</groupId>
    <artifactId>hibernate-community-dialects</artifactId>
</dependency>
spring.jpa.database-platform=org.hibernate.community.dialect.SQLiteDialect

基于:https://discourse.hibernate.org/t/sqlite-not-working-with-hibernate-6-2/8174/2

© www.soinside.com 2019 - 2024. All rights reserved.