SessionFactory启动找不到hbm文件

来源:互联网 发布:mac applications 编辑:程序博客网 时间:2024/05/18 01:22

异常信息:


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [User.hbm.xml] cannot be opened because it does not existat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4521)at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5004)at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:4999)at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)at java.util.concurrent.FutureTask.run(FutureTask.java:138)at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)at java.lang.Thread.run(Thread.java:619)Caused by: java.io.FileNotFoundException: class path resource [User.hbm.xml] cannot be opened because it does not existat org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:677)at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)... 20 more

工程目录:

                


ApplicationContext.xml中配置SessionFactory。

                <property name="mappingResources"><list><value>User.hbm.xml</value></list></property>

修改后文件:

                <property name="mappingResources"><list><value>com/yanzi/bean/User.hbm.xml</value></list></property>
 

这样修改就没有异常信息了。修改后的配置文件,会在你的WebRoot\WEB-INF\classes\com\yanzi\bean下面创建一个hbm配置文件。tomcat指向你的webroot去查找这个文件。修改后的作用就是把这个配置文件添加到编译好的classes里面。可以说算是路径问题吧。


0 0
原创粉丝点击