如果您的项目出现如下问题:
Exception in thread "main" 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 resource bean/WaterInfo.hbm.xml
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
...
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource bean/WaterInfo.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:588)
...
Caused by: org.hibernate.MappingException: Could not parse mapping document in input stream
at org.hibernate.cfg.AnnotationConfiguration.addInputStream(AnnotationConfiguration.java:771)
...
Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
...
按照网上的说法,您把applicationContext.xml中的<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 改成<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">后 。
新的问题又出现了,如下所示:
Exception in thread "main" 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.MappingException: An AnnotationConfiguration instance is required to use <mapping class="bean.WaterInfo"/>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)...
原因:SSH框架的版本之间不兼容。
解决办法:您应该果断地重建项目,更换SSH框架的版本。
如果您项目的框架的更改为:Spring3.1.1、Hibernate4.1.4、Struts2.1,项目运行时可能会出现如下问题:
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:324)
at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:235)
at org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:457)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:393)
at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343)
如出现上述问题,您可到http://www.cnblogs.com/lihuiyy/archive/2013/03/21/2972641.html查看问题出现的原因及解决方法。