Java / Spring异常线程“主要” java.lang.NoClassDefFoundError:org / springframework / beans / factory / ListableBeanFactory

时间:2018-07-31 13:01:04

标签: java spring multithreading main

我目前正在独自学习一种新语言:Java和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 Application运行程序:

 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

我认为我需要创建一个ResourcesController(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";
    }
}

但是,它不会改变任何事情。

因为我是新手,所以我确实需要帮助。 谢谢。

1 个答案:

答案 0 :(得分:0)

正如@mallikarjun所述,我应该

删除.m2文件夹,然后再次运行或再次更新依赖项