3

I'm following the official spring boot guide:

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

My Machine Info:

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>

And the Code:

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);
    }
}

but I get the following Exception every time I try to mvn package && java -jar example.jar , using apache maven 3 and java 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)

Thanks,

3
  • 2
    I can't tell why from your pom, but it looks like you've got an old version of spring-core on the classpath, where loadFactoryNames is private. What is in the lib directory of the jar that you're running? Commented Sep 20, 2014 at 21:54
  • Thanks @AndyWilkinson you are right, there were old spring jars in the extension folder of java ( in my case /Library/Java/Extensions/ ) , I removed them and everything is fine now, I'll add this as an answer. Commented Sep 22, 2014 at 22:27
  • @AndyWilkinson same for me with org.glassfish.jersey.ext:jersey-spring3:2.22.2, thx a lot Commented May 20, 2016 at 19:06

1 Answer 1

2

I'll answer my question based on the helpful note that's mentioned by @AndyWilkinson in the question comments, There were old spring jars (3.2) in /Library/Java/Extensions/ (it's MAC OSX path ) , I've removed them. Now java loads apache Maven jars.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.