Web开发:class path resource [com/xxx/entity/User.hbm.xml] cannot be opened because it doesn't exist
1 前言
最近在教人使用SpringMVC,在运行过程中,有不少人遇到了这个问题,即“class path resource [com/xxx/entity/User.hbm.xml] cannot be opened because it doesn't exist”,但在项目的工程目录中,.hbm.xml又确实存在,这个问题如此诡异,所以特此在这里进行记录。
2 环境和工具
SpringMVC4.3.18,Hibernate5.4.3.Final,Idea。
3 解决方案
先去你的项目的classes目录下,检查classes编译文件夹的同名目录下是否存在你的映射文件。因为Spring在加载映射文件时加载的是你classes编译文件夹下的配置文件而不是你src目录下的。所以很多人出问题出在这一步,classes目录下只有class字节码文件并没有与之对应的xml文件。所以有些同学将其手动复制进去,但是只要一clean,文件就又被清除了,是不是很诡异?其实,一切都是很简单的一个原因。因为没有在pom文件中配置如下设置:
<resources><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes><filtering>true</filtering></resource>
</resources>
只要配置了,一切就恢复正常了,如果配置之后又出现找不到applicationContext.xml的错误,可以在加上,如下代码:
<resources><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes><filtering>true</filtering></resource><resource><directory>src/main/resources</directory><includes><include>*</include></includes><filtering>true</filtering></resource></resources>
一切问题迎刃而解,哈哈哈。
当然啦,如果你不是因为这个问题,这里提供其他的参考建议:
1:检查xxx.hbm.xml文件的class中的name全路径是否正确。有时候你通过逆向工程的生成的的映射文件的全类名和你映射文件的包名是不同的。
2:clean项目重新加载Tomcat。
3:检查导入hibernate的映射文件的方法是否正确。
Web开发:class path resource [com/xxx/entity/User.hbm.xml] cannot be opened because it doesn't exist相关推荐
- class path resource [a.hbm.xml] cannot be opened because it does not exist
大家好,我是mythSun. 很高兴能在这里和大家分享,怎么来解决 class path resource [a.hbm.xml] cannot be opened because it does n ...
- class path resource [beans.xml] cannot be opened because it does not exist
严重: Exception sending context initialized event to listener instance of class org.springframework.we ...
- idea中Web项目 class path resource [applicationContext.xml] cannot be opened because it does not exist
前言: 今天重新整理了一下以前的SSM项目,之后更改了一下所在目录位置,报了这个错. 解决办法:谢谢这个博主,很详细. https://blog.csdn.net/sinat_38301574/art ...
- SpringBoot:class path resource [xxxx.xml] cannot be opened because it does not exist
今天在写微信支付退款功能的时候遇到这样的画一个问题,发现证书找不到,给大家看一下我的文件夹目录 然后我的路径是这样写的 private static String certPath = "r ...
- I DEA出现Spring配置错误:class path resource [.xml] cannot be opened because it does not exist
出现此类异常意思就是没有找到你的 .xml 配置文件 1.解决方法 在src/main目录下新建一个文件夹,建议取名resources 2.点击 File -> Project Structur ...
- IOException parsing XML document from class path resource resource [com/zj/spring01/helloworld/appli
之前学习Spring的时候一直用的Myeclipse和eclipse编辑器,将配置文件直接放进当前Project下进行加载解析就行了.但是换成IEDA以后出现了一些问题.重温Spring知识点的时候, ...
- 【已解决】IOException parsing XML document from class path resource [xxx.xml]
报错异常 IOException parsing XML document from class path resource [xxx.xml]; nested exception is java.i ...
- IOException parsing XML document from class path resource [xxx.xml]
最近在idea导入项目的时候,加载xml文件失败,后台报了如下异常,xml文件没找到. org.springframework.beans.factory.BeanDefinitionStoreExc ...
- class path resource [applicationContext.xml] cannot be opened because it does not exis
使用maven创建web工程,将spring配置文件applicationContext.xml放在src/resource下,用eclipse编译时提示class path resource [ap ...
最新文章
- 混合密度网络(MDN)进行多元回归详解和代码示例
- linux 下使用crontab 定时打包日志并删除已被打包的日志
- 服务器唯一id生成规则
- this computer does not support Intel Virtualization Technology (VT-x) .Haxm can'not be installed
- 程序异常是python语言基本控制结构_计算机二级python 知识点篇(程序的控制结构)...
- codeforces 767C - Garland
- 本地操作HDFS报错:java.net.ConnectException: Call From KevinWong/192.168.16.1 to hadoop000:9000
- 软件测试技术——软件测试概述
- pytorch学习 入门篇(一)
- 那些大学简称背后的“爱恨情仇”:东西南北中,就剩北大没人抢了
- 玩转ptrace (一)
- Linux之at命令
- ZooKeeper CentOS7上安装
- BeanUtils —— 操作JavaBean 工具 学习笔记
- 下载并安装 Azure Data Studio
- oracle32 plsql,32位plsql developer连接64位oracle
- nvidia 卸载驱动
- Micro LED 巨量转移技术
- 苹果mac启动台变成问号_MAC开机停止响应并出现闪烁问号的解决方法
- Ubuntu安装拼音输入法
热门文章
- Android Studio 报错:No variants found for ‘app‘
- Cocos2D-X《街机拳皇》游戏截图
- P1595 信封问题
- Flink实战问题(三): Failed to rollback to checkpoint/savepoint
- (免费分享)基于springboot实习管理系统
- pycharm2019界面的中文设置,有汉化包、有详细步骤、有图片
- 三点照明的三dmax四种基本方法
- 图构造总结-Graph‑based semi‑supervised learning via improving the quality of the graph dynamically
- 关于linux环境下访问Windows数据库的处理方法
- 华为云计算之远程复制