【问题标题】:java.lang.NoClassDefFoundError: org/springframework/core/NativeDetectorjava.lang.NoClassDefFoundError: org/springframework/core/NativeDetector
【发布时间】:2021-03-21 15:57:31
【问题描述】:

我正在用这个tutorial 复习spring,并在JPARepository 上遇到以下依赖问题:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userPersistence' defined in persistence.UserPersistence defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/NativeDetector

UserPersistence 类是这样的:

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;


@RepositoryRestResource()
public interface UserPersistence extends JpaRepository<UserDAO, Integer>, JpaSpecificationExecutor<UserDAO>, QuerydslPredicateExecutor<UserDAO> {}

我正在使用这个build.gradle:

plugins {
    id 'org.springframework.boot' version '2.3.9.RELEASE'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'org.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation group: 'org.springframework.data', name: 'spring-data-commons', version: '2.4.5'
    implementation group: 'com.querydsl', name: 'querydsl-jpa', version: '4.4.0'
    implementation group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
    implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'com.h2database:h2'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

非常感谢任何对此问题有任何了解的人!

【问题讨论】:

  • 尝试将 spring boot 更新到 2.4.3
  • 这个异常听起来像是一个依赖问题,它可能发生在以下情况:实施组:'org.springframework.data',名称:'spring-data-commons',版本:'2.4。 5' 我不太确定 data-commons 2.4.5 是否与 spring 版本 2.3.9 兼容。试试glovemobile的方法。如果它不起作用,您应该检查该类是否存在于:org/springframework/core/
  • 将 spring boot 版本更新到 2.4.4 成功,感谢您的帮助!
  • @glovemobile 请发表您的评论作为答案,以便获得投票和接受。

标签: java spring gradle spring-data-jpa spring-data


【解决方案1】:

基于https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/,您应该使用spring boot 2.4.3。谢谢@Jens Schauder。

【讨论】:

  • 版本 2.4.4 :)
【解决方案2】:

当我将 spring 核心版本更改为 5.3.8 时,它对我有用

我在 pom.xml 中更新了以下条目

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.3.8</version>
        </dependency>

【讨论】:

    猜你喜欢
    • 2021-06-27
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 2018-10-06
    • 2019-12-16
    • 1970-01-01
    • 2013-04-06
    相关资源
    最近更新 更多