gpt4 book ai didi

spring - 在Spring的哪里,如何在Spring Boot中解决 “java.lang.NoClassDefFoundError: org/springframework/data/mapping/context/MappingContext”?

转载 作者:行者123 更新时间:2023-12-03 05:07:07 27 4
gpt4 key购买 nike

我正在使用Java 8和Spring Boot。试图构建一个位于MongoDB上的简单REST应用程序。我在Gradle构建文件中拥有此文件

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.1.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-web:2.1.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-dependencies:2.1.5.RELEASE'
}

但是当我启动我的应用程序时,出现无法找到类“org / springframework / data / mapping / context / MappingContext”的错误:
localhost:todoapp-backend davea$ java -jar ./build/libs/spring-data-mongodb-example-1.0.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/data/mapping/context/MappingContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethod(Class.java:2128)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mapping.context.MappingContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

我应该包括哪些其他依赖项以找到丢失的类?

最佳答案

您应该使用Springboot Gradle插件。它将解决您所有的依赖问题。

plugins {
id 'java
id 'org.springframework.boot' version '2.1.5.RELEASE'
}
apply plugin: 'io.spring.dependency-management'

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
}

关于spring - 在Spring的哪里,如何在Spring Boot中解决 “java.lang.NoClassDefFoundError: org/springframework/data/mapping/context/MappingContext”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56211411/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com