我正在阅读这个教程,以巩固关于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()
}
感谢对此问题有任何了解的人!
implementation group: 'org.springframework.data', name: 'spring-data-commons', version: '2.4.5'
我不确定 data-commons 2.4.5 是否与 Spring 版本 2.3.9 兼容。尝试使用 glovemobile 的方法。如果不起作用,应该检查类是否在以下位置:org/springframework/core/ - Forgotten Dreamer