Error creating bean with name 'sessionFactory' defined in class path resource

Error:

  1. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from input stream  
  2.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)  
  3.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)  
  4.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)  
  5.     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)  
  6.     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)  
  7.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)  
  8.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)  
  9.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)  
  10.     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)  
  11.     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)  
  12.     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)  
  13.     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)  
  14.     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)  
  15.     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)  
  16.     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)  
  17.     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
  18.     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)  
  19.     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)  
  20.     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)  
  21.     at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)  
  22.     at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)  
  23.     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)  
  24.     at java.util.concurrent.FutureTask.run(FutureTask.java:262)  
  25.     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
  26.     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
  27.     at java.lang.Thread.run(Thread.java:744)  
  28. Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream  
  29.     at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:4009)  
  30.     at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3998)  
  31.     at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3986)  
  32.     at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)  
  33.     at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)  
  34.     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:720)  
  35.     at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)  
  36.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)  
  37.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)  
  38.     ... 25 more  
控制台显示是sessionFactory的init方法(即初始化)失效,于是我很自然的去找ApplicationContex.xml文件中sessionFactory的配置段,可是检查了一段下来之后并没有发现什么不妥,紧接着看到下面一行 Could not parse mapping document from input stream,想着是不是映射文件出了问题?查到映射文件,发现标签上name属性没有配置,所以导致了实体类中的属性和数据库中对应的表格字段不符,因此抛出了异常信息。

结论:数据库表字段和实体类属性不一致时会产生该异常(org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from input stream)



正确的是 


你可能感兴趣的:(软件异常)