mappingLocations、mappingDirectoryLocations與mappingJarLocations 區別
因爲spring對hibernate配置文件hibernate.cfg.xml的集成至關好,
因此,在項目中我一直使用spring的org.springframework.orm.hibernate.LocalSessionFactoryBean來取代hibernate.cfg.xml文件的功能
LocalSessionFactoryBean有好幾個屬性用來查找hibernate映射文件:mappingResources、mappingLocations、mappingDirectoryLocations與mappingJarLocations
他們的區別:
mappingResources:指定classpath下具體映射文件名
petclinic.hbm.xml
mappingLocations:能夠指定任何文件路徑,而且能夠指定前綴:classpath、file等
/WEB-INF/petclinic.hbm.xml
classpath:/com/company/domain/petclinic.hbm.xml
也能夠用通配符指定,????*????指定一個文件(路徑)名,????**????指定多個文件(路徑)名,例如:
classpath:/com/company/domain/**/maps/*.hbm.xml
上面的配置是在com/company/domain包下任何maps路徑下的hbm.xml文件都被加載爲映射文件
mappingDirectoryLocations:指定映射的文件路徑
mappingJarLocations:指定加載的映射文件在jar文件中spring