Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未找到xxx.hbm.xml,但它实际存在_Java_Hibernate_Hbmxml - Fatal编程技术网

Java 未找到xxx.hbm.xml,但它实际存在

Java 未找到xxx.hbm.xml,但它实际存在,java,hibernate,hbmxml,Java,Hibernate,Hbmxml,我在运行Tomcat时出现以下错误: 原因:org.springframework.beans.factory.BeanCreationException: 创建在类路径资源[beans.xml]中定义的名为“sessionFactory”的bean时出错:调用init方法失败;嵌套异常是 org.hibernate.MappingNotFoundException:资源: 找不到com/itheima/elec/domain/ElecText.hbm.xml 但它确实存在于我的项目中: 在我

我在运行Tomcat时出现以下错误:

原因:org.springframework.beans.factory.BeanCreationException:
创建在类路径资源[beans.xml]中定义的名为“sessionFactory”的bean时出错:调用init方法失败;嵌套异常是
org.hibernate.MappingNotFoundException:资源:
找不到com/itheima/elec/domain/ElecText.hbm.xml

但它确实存在于我的项目中:

在我的Hibernate配置中,如下所示:

<session-factory>
    ...
    <mapping resource="com/itheima/elec/domain/ElecText.hbm.xml"/>
    <mapping resource="com/itheima/elec/domain/ElecCommonMsg.hbm.xml"/>
</session-factory>

...

我不知道问题出在哪里,有朋友能帮我吗?

请对域文件夹中的类使用@Annotations,这样您就不需要使用hbm.xml文件了。然后在hibernate.cfg.xml文件中使用
''

如果您使用的是maven,那么hbm.xml文件应该位于src/main/resources/com/itheima/…您看到的位置不对:您的屏幕截图显示的是源文件夹,而错误是运行时文件夹(无论是在junit测试中,还是在prod服务器上部署的webapp)。如果在运行时未找到资源,则需要检查运行时类路径,并在此类路径上搜索缺少的资源。如果您需要这方面的帮助,则需要包含有关生成此错误的运行时的更多信息。使用tomcat,查看文件夹:/WEB-INF/classes/com/…中war的内部内容。。。您应该在那里找到hbm.xml(如果与webapp位于同一模块中)