mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations

因为spring对hibernate配置文件hibernate.cfg.xml的集成至关好 
LocalSessionFactoryBean有好几个属性用来查找hibernate映射文件:spring

mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations 
他们的区别: 
1. mappingResources:指定classpath下具体映射文件名 
<property name="mappingResources"> 
<value>petclinic.hbm.xml </value> 
< /property> 
2. mappingLocations:能够指定任何文件路径,而且能够指定前缀:classpath、file等 
<property name="mappingLocations"> 
<value>/WEB-INF/petclinic.hbm.xml </value> 
< /property> 
< property name="mappingLocations"> 
<value>classpath:/com/company/domain/petclinic.hbm.xml </value> 
< /property> 
也能够用通配符指定,'*'指定一个文件(路径)名,'**'指定多个文件(路径)名,例如: 
<property name="mappingLocations"> 
<value>classpath:/com/company/domainmaps/*.hbm.xml </value> 
< /property> 
上面的配置是在com/company/domain包下任何maps路径下的hbm.xml文件都被加载为映射文件 

3. mappingDirectoryLocations:指定映射的文件路径app

<property name="mappingDirectoryLocations">
<list>
<value>WEB-INF/HibernateMappings</value>
</list>
< /property>
也能够经过classpath来指出
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/XXX/package/</value>
</list>
< /property>

4. mappingJarLocations:指定加载的映射文件在jar文件中
相关文章
相关标签/搜索