`

Struts+Spring+Hibernate事务Spring配置

阅读更多

Spring中事务配置如下:

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">


 <bean id="dataSource"
  class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName"
   value="com.mysql.jdbc.Driver">
  </property>
  <property name="url"
   value="jdbc:mysql://localhost:3306/testdata">
  </property>
  <property name="username" value="root"></property>
  <property name="password" value="root"></property>
 </bean>
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.MySQLDialect
    </prop>
   </props>
  </property>
  <property name="mappingResources">
   <list>
    <value>com/hyyg/daos/User.hbm.xml</value>
   </list>
  </property>
 </bean>
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref local="sessionFactory" />
  </property>
 </bean>
 <bean id="UserDAO" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager">
   <ref local="transactionManager" />
  </property>
  <property name="target">
   <ref local="userTarget" />
  </property>
  <property name="transactionAttributes">
   <props>
    <prop key="find*">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>
 
 <bean id="userTarget" class="com.hyyg.daos.UserDAO">
  <property name="sessionFactory">
   <ref local="sessionFactory" />
  </property>
 </bean>
</beans>

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/freeglad/archive/2008/07/20/2681508.aspx

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics