spring配置中mappingResources和mappingLocations
来源:互联网 发布:vscode spring boot 编辑:程序博客网 时间:2024/05/29 19:50
今天真是可笑啊,在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/
- spring配置中mappingResources和mappingLocations
- mappingResources和mappingLocations
- mappingResources和mappingLocations
- hibernate 配置 mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
- spring配置文件中的mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations区别
- Spring 查找hibernate映射文件:mappingResources、mappingLocations、mappingDirectoryLocations与mappingJarLocatio
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations配置映射文件时的区别
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations区别
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations区别
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations 区别
- Spring hibernate配置中mappingLocations、mappingDirectoryLocations与mappingJarLocations 区别
- Spring hibernate配置中mappingLocations、mappingDirectoryLocations与mappingJarLocations 区别
- hive优化
- 【@property的特性】
- Hibernate单向关联1-N
- 【暑期基础2】O HDU 2040 亲和数
- iOS绘图API的使用
- spring配置中mappingResources和mappingLocations
- mysql左连和右连
- hdoj 5289 Assignment 【RMQ + 二分查找区间最优长度】
- mysql 连接url中useUnicode=true&characterEncoding=UTF-8 的作用
- 字典的常用方法(含可变字典)
- mysql 连接url中useUnicode=true&characterEncoding=UTF-8 的作用
- Android UI学习之ListView(使用BaseAdapter)
- Windows Git SSH keys:
- PHP会话初阶