简体   繁体   English

Maven简单项目中springApplication中的IllegalAccessError

[英]IllegalAccessError in springApplication in maven simple project

I'm trying to run a simple application in maven after adding the Spring Jars 3.2.5.RELEASE , my Eclipse is 3.8.3.RELEASE, and I'm getting this error: 添加Spring Jars 3.2.5.RELEASE之后 ,我试图在Maven中运行一个简单的应用程序,我的Eclipse是3.8.3.RELEASE,并且出现此错误:

Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(Ljava/lang/Class;Ljava/lang/ClassLoader;)Ljava/util/List; from class org.springframework.boot.SpringApplication
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:402)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:394)
at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:261)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at Main.main(Main.java:8)

My main: 我的主要:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Main {

   public static void main(String[] args) {
      SpringApplication.run(Main.class, args);

   }

}

My pom.xml: 我的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>io.javabrains.springbootquickstart</groupId>
  <artifactId>course-api</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>TrySpring</name>

<parent>

  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.4.2.RELEASE</version>

</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

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


</project>

I've also tried using STS but I get the same error. 我也尝试过使用STS,但出现相同的错误。

Why are you using such an old version of Spring with the newest version of spring boot? 您为什么要使用如此旧版本的Spring和最新版本的Spring Boot? I would suspect the issue is a class path collision where the 3.2.5 release is getting referenced instead of the appropriate 4.xx jar for a newer spring boot application. 我怀疑问题是类路径冲突,其中引用了3.2.5版本,而不是用于较新的spring boot应用程序的相应4.xx jar。

When you use the starter poms like you are, all the required jars (a ton of excess actually) get included for your use, you shouldn't need to specifically include any spring jars on your path. 当您像以前一样使用入门级poms时,所有需要的jar(实际上是一吨多余的)都会被包括在内以供您使用,您在路径上不需要专门包括任何spring jars。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM