spring 加载Hiberante配置文件
第一种如果不嫌麻烦的话,一个一个的写,或者*.hbm.xml不再同一个目录下,可以使用mappingResources 属性。
如
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<!--
<prop key="hibernate.hbm2ddl.auto">update</prop>
-->
</props>
</property>
<property name="mappingResources">
<list>
<value>com/model/Dict.hbm.xml</value>
<value>com/model/ConfPayroll.hbm.xml</value>
<value>com/model/User.hbm.xml</value>
</list>
</property>
</bean>
如果*.hbm.xml在同一个目录下,可以使用 mappingLocations,可以用通配符表示加载的配置文件
如:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingLocations">
<list>
<value>classpath:/com/model/*.hbm.xml</value>
</list>
</property>
</bean>