java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCre

原创 2016年05月24日 19:09:02

最近做项目遇到一个很难解决的错误,错误日志如下:


java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:232) ~[spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:618) ~[spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467) ~[spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) [catalina.jar:7.0.42]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) [catalina.jar:7.0.42]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.42]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.42]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.42]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [na:1.7.0_13]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) [na:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_13]
    at java.lang.Thread.run(Thread.java:722) [na:1.7.0_13]
五月 24, 2016 7:07:26 下午 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:232)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:618)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

五月 24, 2016 7:07:26 下午 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
五月 24, 2016 7:07:26 下午 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors
五月 24, 2016 7:07:26 下午 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
2016-05-24 19:07:26.858 [localhost-startStop-1] INFO  o.s.w.c.s.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Tue May 24 19:07:24 CST 2016]; root of context hierarchy
2016-05-24 19:07:26.875 [localhost-startStop-1] WARN  o.s.w.c.s.XmlWebApplicationContext - Exception thrown from ApplicationListener handling ContextClosedEvent
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Tue May 24 19:07:24 CST 2016]; root of context hierarchy
    at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:346) [spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333) [spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:880) [spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841) [spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980) [catalina.jar:7.0.42]
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626) [catalina.jar:7.0.42]
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232) [catalina.jar:7.0.42]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160) [catalina.jar:7.0.42]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.42]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.42]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [na:1.7.0_13]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) [na:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_13]
    at java.lang.Thread.run(Thread.java:722) [na:1.7.0_13]
2016-05-24 19:07:26.875 [localhost-startStop-1] WARN  o.s.w.c.s.XmlWebApplicationContext - Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Tue May 24 19:07:24 CST 2016]; root of context hierarchy
    at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:359) [spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:888) [spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841) [spring-context-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980) [catalina.jar:7.0.42]
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626) [catalina.jar:7.0.42]
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232) [catalina.jar:7.0.42]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160) [catalina.jar:7.0.42]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.42]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.42]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [na:1.7.0_13]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) [na:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_13]

    at java.lang.Thread.run(Thread.java:722) [na:1.7.0_13]


 其中项目配置如下:Spring+Mybatis,其中mybatis使用代理开发。

  其中扫描配置如下:

           <!-- 扫描basePackage下所有以@MyBatisRepository标识的 接口-->
          <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
                   <property name="basePackage" value="com.baidu.mybatis" />
                   <property name="annotationClass" value="com.baidu.mybatis.MyBatisRepository"/>
          </bean>

     

   值得需要注意的是,在配置MapperScannerConfigurer时,这里并没有指定sqlSessionFactoryName以及 sqlTemplateName。在没有指定的情

况下,spring就会指定默认的查找规则进行查询,如分别查找到默认的sqlSessionFactory实现和sqlSessionTemplate实现,并注入到

MapperFactoryBean中。

这种配置方式,在一个数据源时,没有问题,但是在如果存在多个数据源时,上面的配置就存在问题了。在多个数据源时,如果配置不正确,或者配置

的步骤不正确,将直接产生莫名奇妙的问题。

      我的项目是当上边的配置在代理mapper不超过100个时,没有问题。当超过180个左右时就出现这种问题。

      经过上网查找终于解决问题,Mybatis 小组写的这个 mybatis-spring plugin 可能存在一些问题,在Spring推出官方的 mybatis-spring plugin。

   



版权声明:本文为博主原创文章,未经博主允许不得转载。

怎么解决java.lang.NoClassDefFoundError错误

前言在日常Java开发中,我们经常碰到java.lang.NoClassDefFoundError这样的错误,需要花费很多时间去找错误的原因,具体是哪个类不见了?类明明还在,为什么找不到?而且我们很容...
  • jamesjxin
  • jamesjxin
  • 2015年06月23日 15:22
  • 428516

Junit 抛出错误 java.lang.NoClassDefFoundError: Could not initialize class org.springframework.test.conte

Junit 抛出错误java.lang.NoClassDefFoundError: Could not initialize class org.springframework.test.contex...
  • LOPYasd
  • LOPYasd
  • 2017年04月18日 10:38
  • 1550

java.lang.NoClassDefFoundError: org/springframework/core/io/Resource

严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis...
  • qq_30938705
  • qq_30938705
  • 2018年02月05日 09:56
  • 188

java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware

最近整理了struts常用的jar包和配置文件,新建项目习惯性的把整个文件夹拷贝进去,启动tomcat报如下错误: Unable to load configuration. - bean - ja...
  • liuyuhua0066
  • liuyuhua0066
  • 2011年04月22日 08:55
  • 8487

mybatis错误org.springframework.beans.factory.BeanCreationException: Could not autowire field

这个问题真的是整的头都大了。 整了 2 3天,还是幸好别人帮忙解决了, 毕竟也是自己忘性大 再加上,不够细心吧,眼力 差了点一直在网络上 查 springmvc 报这样的错误的原因本来就觉得...
  • kongbaidepao
  • kongbaidepao
  • 2015年11月03日 13:57
  • 6694

java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4jLoggerFactory

(一) 现象与解决方法前些天在进行storm job的开发时候突然报了一个错误,记录一下Caused by: java.lang.NoClassDefFoundError: Could not ini...
  • ouyang111222
  • ouyang111222
  • 2015年11月07日 12:00
  • 20212

java.lang.NoClassDefFoundError:could not initial class xxxxxxxxx

/*Thrown if the Java Virtual Machine or a ClassLoader instance * tries to load in the definition...
  • wangjun5159
  • wangjun5159
  • 2016年10月01日 18:46
  • 4295

java.lang.NoClassDefFoundError: Could not initialize class XXX

估计会有好多博友有到过相同的问题,手足无措,我也遇到过这个有关Spring框架的坑爹问题,其实问题如果查到原因了,就会觉得好简单,就好比科学家们计算数字里面少了一个小数点的问题,废话不多说,说下我的解...
  • mdw0730
  • mdw0730
  • 2017年09月22日 17:35
  • 825

java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4jLoggerFactory

(一) 现象与解决方法 前些天在进行storm job的开发时候突然报了一个错误,记录一下 [code]Caused by: java.lang.NoClassDefFoundError: C...
  • mingtianhaiyouwo
  • mingtianhaiyouwo
  • 2016年04月27日 18:45
  • 1156

java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4

(一) 现象与解决方法 前些天在进行storm job的开发时候突然报了一个错误,记录一下 Caused by: java.lang.NoClassDefFoundError: Could n...
  • w1014074794
  • w1014074794
  • 2016年07月12日 20:48
  • 5999
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCre
举报原因:
原因补充:

(最多只允许输入30个字)