Home Spring "hello world" example error: A JNI error has occured & NoClassDefFoundError: org/springframework/beans/factory/ListableBeanFactory
Reply: 1

Spring "hello world" example error: A JNI error has occured & NoClassDefFoundError: org/springframework/beans/factory/ListableBeanFactory

Jenning Lang
1#
Jenning Lang Published in 2016-12-16 04:11:35Z

I tried to use Eclipse to run the Spring Framework "Quick Start" tutorial at http://projects.spring.io/spring-framework/

I firstly built a Maven Project in Eclipse, and added three .java files. The codes are as follows

package hello;

public interface MessageService {
    String getMessage();
}

package hello;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessagePrinter {

    final private MessageService service;

    @Autowired
    public MessagePrinter(MessageService service){
        this.service = service;
    }

    public void printMessage(){
        System.out.println(this.service.getMessage());
    }

}

package hello;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

@Configuration
@ComponentScan
public class Application {

    @Bean
    MessageService mockMessageService(){
        return new MessageService(){
            public String getMessage() {
                return "Hello World!";
            }};
    }

    public static void main(String args[]){
        ApplicationContext context = 
                new AnnotationConfigApplicationContext(Application.class);
        MessagePrinter printer = context.getBean(MessagePrinter.class);
        printer.printMessage();
    }

}

Then I right clicked the Eclipse and choose "run as > Java Application". Two error messages jumped out:

  1. Error: A JNI error has occured, please check your installation and try again

  2. A Java Exception has occurred.

and the console showed

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/beans/factory/ListableBeanFactory at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) 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) at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.privateGetMethodRecursive(Class.java:3048) at java.lang.Class.getMethod0(Class.java:3018) at java.lang.Class.getMethod(Class.java:1784) at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526) Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.ListableBeanFactory 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) ... 19 more

I have tried to add more Spring dependencies (including aop aspects beans context context-support core ...) in the POM file, but that didn't work.

Jenning Lang
2#
Jenning Lang Reply to 2016-12-16 06:43:18Z

I have already fixed this problem. In fact this problem had little relationship to "A JNI error has occured".

The cause of the this problem is that an error(s) occured when Eclipse download Maven dependency jar file, namely "spring-beans".

So I (manually) deleted all the files in "....m2\repository\org\springframework\spring-beans", and used Eclipse to rebuild the project. In this way the problem was fixed.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313012 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO