[英]Spring app cant find hbm.xml mapping file
I am working on a spring mvc app using hibernate and I am having some trouble compiling and running my code. 我正在使用hibernate开发spring mvc应用程序,但是在编译和运行代码时遇到了一些麻烦。
This is because it cannot find my FileObject.hbm.xml whenever I try to create a session factory bean. 这是因为每当我尝试创建会话工厂bean时,它都找不到我的FileObject.hbm.xml。
my bean looks like this 我的豆子看起来像这样
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource1"></property>
<property name="mappingResources">
<list>
<value>FileObject.hmb.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
And the FileObject.hmb.xml resides in the root of my WAR folder. FileObject.hmb.xml驻留在我的WAR文件夹的根目录中。 I have tried to move this file to different folders including the actual src folder and providing the correct path in the session factory but it still gives me a FileNotFoundException.
我曾尝试将此文件移动到其他文件夹,包括实际的src文件夹,并在会话工厂中提供正确的路径,但它仍然给我FileNotFoundException。
Is this because java doesnt recognise a hello.hmb.xml type of file? 这是因为Java无法识别文件hello.hmb.xml类型吗? Most if not all file formats are like this: name.extension
大多数(如果不是全部)文件格式如下:name.extension
hibernate mapping files seems to be different though 休眠映射文件似乎有所不同
Follow-up: As I have noted before, I have tried to put my .hbm.xml in numerous places including the src directory and still wont work. 后续:如前所述,我已尝试将.hbm.xml放置在许多地方,包括src目录,但仍然无法正常工作。
My project structure is similar to this: 我的项目结构与此类似:
(source: springsource.org ) (来源: springsource.org )
I have tried to put the file inside the root dir of war, WEB-INF, classes and as said before, in my actual src directory. 我试图将文件放在war的根目录,WEB-INF,类中,并且如前所述,在我的实际src目录中。
I never knew it was this much hassle just to get hibernate and spring running successfully. 我从来不知道仅仅让冬眠和春天成功运转就这么麻烦。
MappingResources can only receive paths relative to your classpath. MappingResources只能接收相对于您的类路径的路径。
http://forum.springsource.org/showthread.php?t=87988 http://forum.springsource.org/showthread.php?t=87988
If the .hbm.xml files are in a directory tree in your CLASSPATH, try putting the path starting from the root of the CLASSPATH: 如果.hbm.xml文件位于CLASSPATH的目录树中,请尝试将路径从CLASSPATH的根开始:
<value>foo/bar/persistence/hibernate/FileObject.hmb.xml</value>
Directory path I use is just an example. 我使用的目录路径只是一个示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.