1

我的主要

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
4

1 回答 1

0

NullPointerException错误发生在几乎不可能的位置:

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、...


更新

除了您可能试图将 Spring JAR 放入 JRE 的库文件夹( ${java.home}/jre/lib)之外,没有其他解释。如果真是这样,那简直是错误的。如果您真的想在 JRE 中包含外部 JAR,请将它们放在官方扩展目录 - ${java.home}/jre/lib/ext.

于 2013-06-12T21:10:10.177 回答