本文主要是介绍Error creating bean with name 'sessionFactory',希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
出现这个问题的原因极大可能的是 hbm的配置文件出错了,或者根本就没有配置。在控制台的报错信息,下面会有Cause By的信息,会提示是由什么问题引发的。
(1)检查是否配置hbm配置文件
解决办法:
在实体类的同包下添加,即可。
User.hbm.xml 内容<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="cn.itcast.shop.user.vo.User" table="user"><id name="uid"><generator class="native"/></id><property name="username"/><property name="password"/><property name="name"/><property name="email"/><property name="phone"/><property name="addr"/><property name="state"/><property name="code"/><set name="orders" cascade="delete"><key column="uid"/><one-to-many class="cn.itcast.shop.order.vo.Order"/></set></class></hibernate-mapping>
(2)检查配置文件hbm中是否有打错
错误原因由:找不到字段为“tatal”在该包中。 对比发现,是“total”打错了。
这篇关于Error creating bean with name 'sessionFactory'的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!