Spring Error java.lang.NullPointerException

时间:2013-06-12 09:36:17

标签: java eclipse spring

我的主要

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
public static void main(String[] args) {
    System.out.println("hola");
    ApplicationContext context = new   ClassPathXmlApplicationContext("Beans.xml");
    HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
    obj.getMessage();
}
}

Exception in thread "main" java.lang.ExceptionInInitializerError
at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:201)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:127)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:551)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.tutorialspoint.MainApp.main(MainApp.java:9)



Caused by: java.lang.NullPointerException
          at org.springframework.beans.factory.support.
          DefaultListableBeanFactory.<clinit>(DefaultListableBeanFactory.java:108)
          ... 7 more

1 个答案:

答案 0 :(得分:0)

NullPointerException错误几乎为impossible location

static {
    ClassLoader cl = DefaultListableBeanFactory.class.getClassLoader();
    try {
        javaxInjectProviderClass = cl.loadClass("javax.inject.Provider"); /* line 108 */
    } catch (ClassNotFoundException ex) {
        // JSR-330 API not available - Provider interface simply not supported then.
    }
}

这意味着该类无法获得自己的类加载器。你必须做一些非常糟糕的事情才能得到这个错误。检查您的JRE / JDK,IDE,...


更新

There is no explanation除此之外您可能正在尝试将Spring JAR放入JRE的库文件夹${java.home}/jre/lib)。如果是这种情况,那就完全错了。如果您真的想在JRE中包含外部JAR,请将它们放在官方扩展目录中${java.home}/jre/lib/ext