Java.lang.ExceptionInInitializerError 错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactInformationApi': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mysqlOrderService' defined in URL [jar:file:/C:/mySoftware/apache-tomcat-6.0.35/webapps/MA_Server1/WEB-INF/lib/MA_Core.jar!/com/sw/plugins/order/service/mysql/MysqlOrderService.class]: Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:311) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:835) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446) [spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328) [spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) [spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206) [catalina.jar:6.0.35]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705) [catalina.jar:6.0.35]
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057) [catalina.jar:6.0.35]
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840) [catalina.jar:6.0.35]
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057) [catalina.jar:6.0.35]
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) [catalina.jar:6.0.35]
    at org.apache.catalina.core.StandardService.start(StandardService.java:525) [catalina.jar:6.0.35]
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754) [catalina.jar:6.0.35]
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595) [catalina.jar:6.0.35]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_43]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_43]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_43]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_43]
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) [bootstrap.jar:6.0.35]
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) [bootstrap.jar:6.0.35]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mysqlOrderService' defined in URL [jar:file:/C:/mySoftware/apache-tomcat-6.0.35/webapps/MA_Server1/WEB-INF/lib/MA_Core.jar!/com/sw/plugins/order/service/mysql/MysqlOrderService.class]: Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError



引起 Java.lang.ExceptionInInitializerError 错误的原因是:在类的初始化时,出错。也就是说,在加载类时,执行static的属性、方法块时,出错了。

比如

public class AA {

   private static AA aa = new AA(); 

   private AA(){//构造方法

     init();

   }  

 public void init(){

    ....  }

}

初始化类时,会调用init方法,如果Init方法出错,这类初始化失败,就会报java.lang.ExceptionInInitializerError错误

同理,在执行

static{

  ...

}

方法块时,也可能报这个错。

原文地址:http://blog.csdn.net/zollty/article/details/11028337

OrderService中一个static变量初始化有问题,去掉这行,重启通过

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页