在Spring中配置SessionFactory的二种方式
第一种方式:
把Hibernate的配置文件hibernate.cfg.xml配置到applicationContext.xml中
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="file:src/hibernate.cfg.xml"> </property> </bean>
第二种方式:
利用dataSource来配置SessionFactory
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" value="dataSource"></property> <property name="mappingResources"> <list> <value>com/pojo/Guestbook.hbm.xml</value> <value>com/pojo/User.hbm.xml</value> ...... </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> </props> </property> </bean>