gpt4 book ai didi

spring - 执行一个简单的 Spring Boot 应用程序时出现 IllegalAccessError 异常

转载 作者:行者123 更新时间:2023-12-01 16:23:48 26 4
gpt4 key购买 nike

我正在遵循官方的 spring boot 指南:

http://projects.spring.io/spring-boot

我的机器信息:

Apache Maven 3.1.0 
Maven home: /Users/abshammeri/apps/apache-maven-3.1.0
Java version: 1.7.0_11, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"

POM.xml

<groupId>org.test</groupId>
<artifactId>example</artifactId>
<version>0.1.0</version>


<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<properties>
<start-class>hello.Application</start-class>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>

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

和代码:

package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}

public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}

但每次我尝试 mvn package && java -jar example.jar 时,我都会收到以下异常,使用 apache maven 3java 1.7 ,

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:722)
Caused by: 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:367)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:358)
at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:228)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:204)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at hello.Application.main(Application.java:17)

谢谢,

最佳答案

我将根据@AndyWilkinson 在问题评论中提到的有用说明回答我的问题,/Library/Java/Extensions/ 中有旧的 spring jars (3.2)(它是 MAC OSX 路径 ) ,我已经删除了它们。现在 java 加载 apache Maven jar。

关于spring - 执行一个简单的 Spring Boot 应用程序时出现 IllegalAccessError 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25953028/

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