嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/data/mapping/IdentifierAccessor
Posted
技术标签:
【中文标题】嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/data/mapping/IdentifierAccessor【英文标题】:nested exception is java.lang.NoClassDefFoundError: org/springframework/data/mapping/IdentifierAccessor 【发布时间】:2015-09-10 01:37:17 【问题描述】:我正在尝试使用 Spring + JPA + PostgreSQL。
当我点击“调试”时出现异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/mapping/IdentifierAccessor
结构项目是
application.properties
spring.datasource.url = jdbc:postgresql://localhost:5432/gastos
spring.datasource.username = postgres
spring.datasource.password = *******
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL9Dialect
Application.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@SpringBootApplication
public class Application
public static void main(String[] args)
SpringApplication.run(Application.class, args);
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gastos4</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.8.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我没有在网上找到解决方案。我做错了什么?
【问题讨论】:
没有在 CLASSPATH 中添加一些依赖项,这就是 NoClassDefFoundError 所说的......所以看看它引用的类以及它的依赖项是什么 @NeilStockton 对不起,你能告诉我该怎么做吗?我是 Spring 和 Java 世界的新手。 【参考方案1】:尝试将 Spring Data Commons Core 添加到您的 pom 中
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
【讨论】:
IdentifierAccessor - 请参考github.com/spring-projects/spring-data-commons/tree/master/src/… 我添加了 spring-data-commons-1.9.2.RELEASE 并且我收到了一个新错误,上面写着java.lang.NoSuchMethodError: org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(Lorg/springframework/core/type/AnnotationMetadata;Ljava/lang/Class;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;)V
亲爱的,看起来有一些maven依赖版本不匹配【参考方案2】:
我遇到了同样的问题,奇怪的是我通过将依赖 spring-data-jpa 替换为:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>$spring.version</version>
</dependency>
【讨论】:
以上是关于嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/data/mapping/IdentifierAccessor的主要内容,如果未能解决你的问题,请参考以下文章
当我在 Eclipse 中运行 hadoop 作业时出现异常
“Ionic cordova build android”错误
构造函数抛出异常嵌套异常是 java.lang.nullpointerexception
工厂方法“dataSource”抛出异常;嵌套异常是 javax.naming.NameNotFoundException