intellij 编译 springmvc+hibernate+spring+maven 找不到hbm.xml映射文件

1. 错误信息

Invocation of init method failed; nested exception is org.hibernate.MappingNotFoundException: resource: model/Department.hbm.xml not found
at 

2. 错误分析

(1)项目的hibernate****是用intellij的persistant工具来完成的,最终完成后,模型对象和映射文件都保存在了model的目录下。

intellij 编译 springmvc+hibernate+spring+maven 找不到hbm.xml映射文件

(2)由于我们设定了src文件夹是存放代码的,resource文件夹是存放资源的,因此intellij在编译的时候会忽略src文件夹下面的xml文件,导致最后发布的文件夹下面丢失了这些映射文件。

详情参照:http://stackoverflow.com/questions/2843949/how-to-configure-hibernate-tools-with-maven-to-generate-hibernate-cfg-xml-hbm

 intellij 编译 springmvc+hibernate+spring+maven 找不到hbm.xml映射文件

3. 解决方案

在resource的目录下建立同目录同名的文件夹,保存相应的xml文件。

intellij 编译 springmvc+hibernate+spring+maven 找不到hbm.xml映射文件

我的配置:

intellij 编译 springmvc+hibernate+spring+maven 找不到hbm.xml映射文件

说明:

mappingDirectoryLocations:批量读取
mappingResources:读取单个配置文件

 

 

参考:https://www.cnblogs.com/weishenhong/p/5309430.html