Spring与Hibernate的整合

来源:互联网 发布:全景图制作软件 编辑:程序博客网 时间:2024/05/15 00:51

Spring与Hibernate整合方法很简单,就是通过修改xxxContext.xml文件。例如:

 <bean id=sessionFactory class=org.springframework.orm.hibernate3.LocalSessionFactoryBean>
  <property name=dataSource><ref local=dataSource/></property>
  <property name=mappingResources>
   <value>User.hbm.xml</value>
   <value>Role.hbm.xml</value>
  </property>
  <property name=hibernateProperties>
   <props>
    <prop key=hibernate.dialect>${hibernate.dialect}</prop>
    <prop key=hibernate.show_sql>true</prop>
   </props>
  </property>
 </bean>

有时候需要保持Hibernate配置的相对独立。
不希望把ConnectionUrl的信息也都写在Context.xml里面,
可以这样配置:

<bean id=sessionFactory
class=org.springframework.orm.
hibernate.LocalSessionFactoryBean>
<property name=configLocation>
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name=hibernateProperties>
<value>classpath:hibernate.properties</value>
</property>
</bean>

 
原创粉丝点击