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文件中
相關文章
相關標籤/搜索