本文介紹了JAVA/Spring異常線程&Main";java.lang.NoClassDefFoundError:org/springframework/beans/factory/ListableBeanFactory的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我目前正在自學一門新語言:Java with Spring。
我已經設法在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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tech.benjaminpradon</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>benjaminpradon</name>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- Version -->
<properties>
<java.version>1.8</java.version>
</properties>
</project>
我還創建了Spring應用程序運行程序:
package springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class LearningJava {
public static void main(String[] args) {
SpringApplication.run(LearningJava.class, args);
}
}
但是,當我嘗試運行它時,出現錯誤:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/beans/factory/ListableBeanFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at springboot.LearningJava.main(LearningJava.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.ListableBeanFactory
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
我認為我需要創建一個Resources控制器(RestController)。
因此,我創建了一個:
package springboot.hello;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String Hi() {
return "Hi";
}
}
但是,這不會改變任何事情。
因為我是紐比人,我真的需要幫助。
謝謝。
推薦答案
正如@Mallikarjun提到的,我應該
刪除.m2文件夾,然后重新運行或再次更新依賴項
這篇關于JAVA/Spring異常線程&Main";java.lang.NoClassDefFoundError:org/springframework/beans/factory/ListableBeanFactory的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,