gpt4 book ai didi

java - 如何修复 "Exception in thread "main"java.lang.NoClassDefFoundError : org/springframework/core/io/support/SpringFactoriesLoader"in Spring Tool Suite

转载 作者:行者123 更新时间:2023-12-02 09:59:51 27 4
gpt4 key购买 nike

Spring Tool Suite 编辑器在我的代码中没有给出任何错误,但是当我尝试作为 Spring Boot 应用程序运行时,它给了我一个未找到类 def 的异常。我在这里想做的就是运行 Spring Boot 应用程序,它会在控制台中显示 Spring Boot Logo

我已经检查了 xml 文件中的所有依赖项,它们看起来没问题,但并不完全确定。

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/io/support/SpringFactoriesLoader
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:428)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:420)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:268)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:249)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at com.example.ToDoAppApplication.main(ToDoAppApplication.java:10)


Caused by: java.lang.ClassNotFoundException: org.springframework.core.io.support.SpringFactoriesLoader
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

应该只看到 Spring Boot 应用程序在控制台中成功运行,没有任何错误。

这是我的 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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>ToDoApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ToDoApp</name>
<description>ToDoApp for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.3.RELEASE</version><!--$NO-MVN-MAN-VER$-->
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.1.4.RELEASE</version><!--$NO-MVN-MAN-VER$-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version><!--$NO-MVN-MAN-VER$-->
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.1.5.RELEASE</version><!--$NO-MVN-MAN-VER$-->
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.1.5.RELEASE</version><!--$NO-MVN-MAN-VER$-->
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.security/org.springframework.security.config -->
<!-- <dependency>
<groupId>org.springframework.security</groupId>
<artifactId>org.springframework.security.config</artifactId>
<version>3.1.3.RELEASE</version>
</dependency> -->


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

最佳答案

你的依赖关系一团糟。您正在混合不兼容的版本,因此会出现错误。清理 pom.xml 中的依赖项.

<dependencies>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

删除spring-core依赖关系,这可能是罪魁祸首。不要使用<version />包含起始符时的标签,这些标签是通过父级管理的。使用 spring-boot-starter-security 而不是单独的 Spring Security 依赖项反而。您还有重复的mysql-connector-java依赖关系。

关于java - 如何修复 "Exception in thread "main"java.lang.NoClassDefFoundError : org/springframework/core/io/support/SpringFactoriesLoader"in Spring Tool Suite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55716659/

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