LocalSessionFactoryBean有几个属性查找hibernate映射文件:
mappingResources、mappingLocations、mappingDirectoryLocations与mappingJarLocations
1、String[] mappingResources: 指定classpath下具体映射文件名
- <property name="mappingResources">
- <list>
- <value>cn/itcast/domain/User.hbm.xml</value>
- <value>cn/itcast/domain/Department.hbm.xml</value>
- </list>
- lt;/property>
2、Resource[] mappingLocations:指定任何文件路径,可以指定前缀:classpath、file等
- <propertynamepropertyname="mappingLocations"value="/WEB-INF/Pojot.hbm.xml"/>
- <propertynamepropertyname="mappingLocations"value="classpath:cn/itcast/domain/User.hbm.xml"/>
- 也可以用通配符指定,'*'指定一个文件(路径)名,'**'指定多个文件(路径)名,例如:
- <property name="mappingLocations">
- <list>
- <value>classpath:cn/itcast/domain/*.hbm.xml</value>
- </list>
- </property>
3、Resource[] mappingDirectoryLocations:指定映射的文件路径
- <property name="mappingDirectoryLocations">
- <list>
- <value>/WEB-INF/classes/cn/itcast/domain</value>
- </list>
- </property>
4、Resource[] mappingJarLocations:指定加载的映射文件在jar文件