<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="
dataSource" class="
org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="
driverClassName">
<value>
com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</property>
<property name="
url">
<value>
jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=addressbook</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>sa</value>
</property>
</bean>
<!-- 配置sessionFactory, 注意这里引入的包的不同 -->
<bean id="
sessionFactory" class="
org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="
dataSource">
<ref local="
dataSource" />
</property>
<property name="
mappingResources">
<list>
<value>
com/netmarch/Hibernate/Userl.hbm.xml</value>
</list>
</property>
<property name="
hibernateProperties">
<props>
<prop key="
hibernate.dialect">
org.hibernate.dialect.SQLServerDialect</prop>
<prop key="
hibernate.show_sql">
true</prop>
</props>
</property>
</bean>
<bean id="
transactionManager" class="
org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="userDAO" class="com.netmarch.dao.daoimp.UserDAOImp">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="userDAOProxy" class="
org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userDAO" />
</property>
<property name="
transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean name="/login" class="com.netmarch.struts.action.LoginAction" singleton="false">
<property name="userDAO">
<ref bean="userDAOProxy" />
</property>
</bean>
</beans>
1. SessionFactory的引入
Hibernate中通过SessionFactory创建和维护Session。Spring对SessionFactory的配置也进行了整合,无需再通过Hibernate.cfg.xml对SessionFactory进行设定。SessionFactory节点的mappingResources属性包含了映射文件的路径,list节点下可配置多个映射文件。hibernateProperties节点则容纳了所有的属性配置。
2. 采用面向Hibernate的TransactionManager实现:org.springframework.orm.hibernate.HibernateTransactionManager
posted on 2006-09-15 11:49
周锐 阅读(1475)
评论(0) 编辑 收藏 所属分类:
Hibernate 、
Spring