---
title: "Struts+Spring+Hibernate事务Spring配置"
author: "leowzy"
date: "2009-10-06T00:44:41Z"
tags: ["Bean", "Hibernate", "MySQL", "Spring", "Struts"]
slug: "struts-spring-hibernate-spring"
draft: false
lastmod: "2009-10-06T00:44:41Z"
id: 482040
url: "https://leowzy.iteye.com/blog/482040"
---

Spring中事务配置如下：

 &lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;beans xmlns="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)"  
 xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
 xsi:schemaLocation="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans) [http://www.springframework.org/schema/beans/spring-beans-2.0.xsd](http://www.springframework.org/schema/beans/spring-beans-2.0.xsd)"&gt;

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

 

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