当前位置: 首页 > 知识库问答 >
问题:

Springboot Maven:更正应用程序的类路径,使其包含类的兼容版本

西门磊
2023-03-14

我在运行Springboot Maven应用程序时遇到问题。这个问题始于一个缺失的依赖关系,这让我无法解决另一个问题,我尝试了来自整个网络的多个建议,但都无济于事。我确实移除了。m2文件夹并重新构建,但同样的错误再次出现。

我控制台中的错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.<init>(PersistenceAnnotationBeanPostProcessor.java:650)

The following method did not exist:

    'javax.persistence.SynchronizationType javax.persistence.PersistenceContext.synchronization()'

The calling method's class, org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement, was loaded from the following location:

    jar:file:/C:/Users/Kevin/.m2/repository/org/springframework/spring-orm/5.3.19/spring-orm-5.3.19.jar!/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor$PersistenceElement.class

The called method's class, javax.persistence.PersistenceContext, is available from the following locations:

    jar:file:/D:/School%20Novi/Eindopdracht/BackEnd/demodrop-be/lib/javax.persistence.jar!/javax/persistence/PersistenceContext.class
    jar:file:/C:/Users/Kevin/.m2/repository/jakarta/persistence/jakarta.persistence-api/2.2.3/jakarta.persistence-api-2.2.3.jar!/javax/persistence/PersistenceContext.class
    jar:file:/C:/Users/Kevin/.m2/repository/javax/persistence/javax.persistence-api/2.2/javax.persistence-api-2.2.jar!/javax/persistence/PersistenceContext.class

The called method's class hierarchy was loaded from the following locations:

    javax.persistence.PersistenceContext: file:/D:/School%20Novi/Eindopdracht/BackEnd/demodrop-be/lib/javax.persistence.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement and javax.persistence.PersistenceContext


Process finished with exit code 1

我的pom。xml:

<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>2.6.7</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demodrop-be</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demodrop-be</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.28</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.xmlunit</groupId>
            <artifactId>xmlunit-core</artifactId>
        </dependency>
    </dependencies>

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

</project>

欢迎任何意见。

共有1个答案

甄德寿
2023-03-14

谢谢大家,删除提到的依赖项解决了这个问题。这一切都始于一个错误,说明javax.persistence未加载,这是由依赖项的不当选择事后造成的。我大约5个月前才开始学习前端和后端开发的在线课程,所以它仍然有点令人生畏。

 类似资料: