材料来源:http://www.blogjava.net/caixuetao/articles/37790.html
通常在spring中会这么写代码
mappingResources
<
bean id
=
"
sessionFactory
"
class
=
"
org.springframework.orm.hibernate.LocalSessionFactoryBean
"
>
< property name = " mappingResources " >
< list >
< value > Student.hbm.xml </ value >
< value > Course.hbm.xml </ value >
…
</ list >
</ property >
…
</ bean >
如果X.hbm.xml文件很多时,则写起来会很不方便,可以像下面这种写法就简单多了:(其中假设所有的.hbm.xml文件都存于com/model目录)
mappingDirectoryLocations< property name = " mappingResources " >
< list >
< value > Student.hbm.xml </ value >
< value > Course.hbm.xml </ value >
…
</ list >
</ property >
…
</ bean >
<
bean id
=
"
sessionFactory
"
class
=
"
org.springframework.
orm.hibernate.LocalSessionFactoryBean " >
< property name = " mappingDirectoryLocations " >
< list >
< value > classpath: / com / model </ value >
</ list >
</ property >
…
</ bean >
orm.hibernate.LocalSessionFactoryBean " >
< property name = " mappingDirectoryLocations " >
< list >
< value > classpath: / com / model </ value >
</ list >
</ property >
…
</ bean >
写到这里,看到classpath,想起以前整合SSH时,在web.xml中也使用过classpath来简化
<
context-param
>
<
param-name
>
contextConfigLocation
</
param-name
>
<
param-value
>
classpath:applicationContext.xml
</
param-value
>
</
context-param
>