1、在applicationContext.xml中引入hibernate.cfg.xml,如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- 使用hibernate自身的配置文件配置 <property name="configLocations"> <list> <value>classpath:cn/itcast/spring/hibernate/hibernate.cfg.xml</value> </list> </property> </bean>
2、将hibernate相关配置配在applicationContext.xml中
<!-- 本地会话工厂bean,spring整合hibernate的核心接口 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- 指定hibernate自身的属性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> </props> </property> <!-- 从指定目录下查找映射文件--> <property name="mappingDirectoryLocations"> <list> <value>cn/itcast/spring/domain</value> </list> </property> <!-- 映射文件的位置 <property name="mappingResources"> <list> <value>cn/itcast/spring/domain/Customer.hbm.xml</value> </list> </property> --> </bean>