首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

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

2012-09-10 
Error creating bean with name sessionFactory defined in class path resourceJava code2009-8-6 9:47

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

Java code
2009-8-6 9:47:06 org.apache.catalina.core.AprLifecycleListener init信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Program Files\MyEclipse 6.0\bin;D:\Program Files\MyEclipse 6.0\myeclipse\eclipse\plugins\com.genuitec.eclipse.easie.tomcat.myeclipse_6.0.1.zmyeclipse601200710\tomcat\bin2009-8-6 9:47:06 org.apache.coyote.http11.Http11Protocol init信息: Initializing Coyote HTTP/1.1 on http-80802009-8-6 9:47:06 org.apache.catalina.startup.Catalina load信息: Initialization processed in 637 ms2009-8-6 9:47:06 org.apache.catalina.core.StandardService start信息: Starting service Catalina2009-8-6 9:47:06 org.apache.catalina.core.StandardEngine start信息: Starting Servlet Engine: Apache Tomcat/6.0.132009-8-6 9:47:08 org.apache.catalina.core.ApplicationContext log信息: Initializing Spring root WebApplicationContextlog4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).log4j:WARN Please initialize the log4j system properly.2009-8-6 9:47:10 org.apache.catalina.core.StandardContext listenerStart严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.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.MappingNotFoundException: resource: com/whda/entity/Immobility.hbm.xml not foundCaused by: org.hibernate.MappingNotFoundException: resource: com/whda/entity/Immobility.hbm.xml not found    at org.hibernate.cfg.Configuration.addResource(Configuration.java:563)    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)    at org.hibernate.cfg.Configuration.configure(Configuration.java:1443)    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:634)    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245)    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188)    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)    at org.apache.catalina.core.StandardService.start(StandardService.java:516)    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    at java.lang.reflect.Method.invoke(Unknown Source)    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)2009-8-6 9:47:10 org.apache.catalina.core.StandardContext start严重: Error listenerStart2009-8-6 9:47:10 org.apache.catalina.core.StandardContext start严重: Context [/hdDate] startup failed due to previous errors2009-8-6 9:47:10 org.apache.catalina.core.ApplicationContext log信息: Closing Spring root WebApplicationContext2009-8-6 9:47:10 org.apache.coyote.http11.Http11Protocol start信息: Starting Coyote HTTP/1.1 on http-80802009-8-6 9:47:10 org.apache.jk.common.ChannelSocket init信息: JK: ajp13 listening on /0.0.0.0:80092009-8-6 9:47:10 org.apache.jk.server.JkMain start信息: Jk running ID=0 time=0/78  config=null2009-8-6 9:47:10 org.apache.catalina.startup.Catalina start信息: Server startup in 4119 ms 



XML code
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools.                   --><hibernate-configuration><session-factory>    <property name="connection.username">sa</property>    <property name="connection.url">        jdbc:sqlserver://localhost:1433;databaseName=hd    </property>    <property name="dialect">        org.hibernate.dialect.SQLServerDialect    </property>    <property name="myeclipse.connection.profile">sql2005</property>    <property name="connection.password">leon</property>    <property name="connection.driver_class">        com.microsoft.sqlserver.jdbc.SQLServerDriver    </property>    <property name="show_sql">true</property>    <property name="connection.autocommit">true</property>    <!--  -->        <mapping resource="com/whda/entity/Immobility.hbm.xml" />    <mapping resource="com/whda/entity/Hdmain.hbm.xml" />    <mapping resource="com/whda/entity/Manhour.hbm.xml" />        </session-factory></hibernate-configuration>


XML code
<?xml version="1.0" encoding="UTF-8"?><beans    xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">    <!-- 配置spring资源库 -->    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">        <property name="basename">            <value>com.whhd.hd.struts.ApplicationResources</value>        </property>    </bean>    <bean id="sessionFactory"        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">        <property name="configLocation" value="classpath:hibernate.cfg.xml">        </property>        <!--          <property name="mappingLocations">            <list>            <value>classpath*:com/whda/entity/Immobility.hbm.xml</value>            <value>classpath*:com/whda/entity/Hdmain.hbm.xml</value>            <value>classpath*:com/whda/entity/Manhour.hbm.xml</value>                          </list>        </property>        -->    </bean>        <!-- DAO -->    <bean id="hdmaindao" class="com.whhd.dao.HdmainDAO">        <property name="sessionFactory">            <ref bean="sessionFactory" />        </property>    </bean>    <bean id="immobilityDAO" class="com.whhd.dao.ImmobilityDAO">        <property name="sessionFactory">            <ref bean="sessionFactory" />        </property>    </bean>    <bean id="manhourDAO" class="com.whhd.dao.ManhourDAO">        <property name="sessionFactory">            <ref bean="sessionFactory" />        </property>    </bean><!-- BIZ -->    <bean id="ihmainImpl" class="com.whhd.biz.IHmainImpl">        <property name="hdmainDAO">            <ref bean="hdmaindao"/>        </property>    </bean>    <bean id="immobilityImpl" class="com.whhd.biz.ImmobilityImpl">        <property name="immobility">            <ref bean="immobilityDAO" />        </property>    </bean>    <bean id="manhourImpl" class="com.whhd.biz.ManhourImpl">        <property name="manhour">            <ref bean="manhourDAO"/>        </property>    </bean><!-- ACTION -->    <bean name="/main" class="com.whhd.struts.action.MainAction">        <property name="ihmainBiz">            <ref bean="ihmainImpl"/>        </property>        <property name="manhourBiz">            <ref bean="manhourImpl"/>        </property>        <property name="immobilityBiz">            <ref bean="immobilityImpl"/>        </property>    </bean>    </beans> 



[解决办法]
Caused by: org.hibernate.MappingNotFoundException: resource: com/whda/entity/Immobility.hbm.xml not found
找不到这个映射文件啊 
看看路径什么的 
删除缓存试试
tomcat目录下的work文件夹下的内容全部删掉 
重启tom试试
[解决办法]
用目录试试,一个映射文件一个的配置多麻烦,直接配置路径,让它自己去找
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/whda/entity</value>
</list>
</property>
[解决办法]
用了spring就直接在spring的配置文件中写hibernate好了 就不用hibernate。cfg。xml了吧

热点排行