spring配置中mappingResources和mappingLocations
2015-08-06 12:52
274 查看
今天真是可笑啊,在spring和hibernate集成的时候,把hibernate的映射文件路径放到”sessionFactory”配置项中。结果报错,说是:
Error creating bean with name ‘sessionFactory’ defined in file [E:\soft\Apache Software Foundation\Tomcat 7.0\webapps\ExamSystem\WEB-INF\classes\applicationContext-db.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [classpath:com/exam/model/*.hbm.xml] cannot be opened because it does not exist
我检查了很久,路径没写错啊,怎么会FileNotFound 呢?于是查看jar包有没有少,web.xml 配置有没有写错,折腾了很久都没发现什么问题。百度、google很久也没找到答案。
最后却发现这是一个脑残的错误!我是这么写的:
classpath:com/exam/model/*.hbm.xml
我完全没注意啊,我以为 mappingResources 里面可以这么写的。后来把“mappingResources ”改成了“mappingLocations”就没问题了。至于它们的区别,摘录一篇文章,地址:http://wukaxi.iteye.com/blog/1401753
内容如下:
mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
他们的区别:
1. mappingResources:指定classpath下具体映射文件名
petclinic.hbm.xml
2. mappingLocations:可以指定任何文件路径,并且可以指定前缀:classpath、file等
/WEB-INF/petclinic.hbm.xml
classpath:/com/company/domain/petclinic.hbm.xml
也可以用通配符指定,’‘指定一个文件(路径)名,’*‘指定多个文件(路径)名,例如:
classpath:/com/company/domainmaps/*.hbm.xml
上面的配置是在com/company/domain包下任何maps路径下的hbm.xml文件都被加载为映射文件
mappingDirectoryLocations:指定映射的文件路径
WEB-INF/HibernateMappings
也可以通过classpath来指出
classpath:/XXX/package/
Error creating bean with name ‘sessionFactory’ defined in file [E:\soft\Apache Software Foundation\Tomcat 7.0\webapps\ExamSystem\WEB-INF\classes\applicationContext-db.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [classpath:com/exam/model/*.hbm.xml] cannot be opened because it does not exist
我检查了很久,路径没写错啊,怎么会FileNotFound 呢?于是查看jar包有没有少,web.xml 配置有没有写错,折腾了很久都没发现什么问题。百度、google很久也没找到答案。
最后却发现这是一个脑残的错误!我是这么写的:
classpath:com/exam/model/*.hbm.xml
我完全没注意啊,我以为 mappingResources 里面可以这么写的。后来把“mappingResources ”改成了“mappingLocations”就没问题了。至于它们的区别,摘录一篇文章,地址:http://wukaxi.iteye.com/blog/1401753
内容如下:
mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
他们的区别:
1. mappingResources:指定classpath下具体映射文件名
petclinic.hbm.xml
2. mappingLocations:可以指定任何文件路径,并且可以指定前缀:classpath、file等
/WEB-INF/petclinic.hbm.xml
classpath:/com/company/domain/petclinic.hbm.xml
也可以用通配符指定,’‘指定一个文件(路径)名,’*‘指定多个文件(路径)名,例如:
classpath:/com/company/domainmaps/*.hbm.xml
上面的配置是在com/company/domain包下任何maps路径下的hbm.xml文件都被加载为映射文件
mappingDirectoryLocations:指定映射的文件路径
WEB-INF/HibernateMappings
也可以通过classpath来指出
classpath:/XXX/package/
相关文章推荐
- iOS绘图API的使用
- Android Studio之新建Studio项目
- iOS 8.4越狱(iPhone6)
- [Android] R cannot be resolved to a variable error
- Object-C 通知
- 【Cocos2d入门教程六】Cocos2d-x事件篇之触摸
- AppDelegate.h
- ABAP 面向对象(Object Orien…
- android - 模仿微博的@人功能
- 如何知道android应用是第一次运行
- ios code test
- Android Bitmap大量使用不产生OOM之多线程并发加载Bitmap的处理方式
- unity场景导出
- Unity内存申请和释放
- Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面
- iosTest
- iOS imageName方法获取Folder文件夹(蓝色文件夹)内图片
- iOS开发无第三方控件的援助达到的效果侧边栏
- Android studio jar冲突编译问题
- Android, xmpp, asmack以及openfire