日期:2014-05-18  浏览次数:20685 次

【新手】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" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-p-3.0.xsd

">


<!--  启用自动扫描
<context:component-scan base-package="com.myEdition"></context:component-scan> -->
<!-- 事务管理  -->
<!-- 以下的被注释
<tx:annotation-driven transaction-manager="transactionManger"/>
<bean id="transactionManger" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
 -->
<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/myedition">
</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"></ref>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<!--   <value>com/myEdition/bean/Content.hbm.xml</value>
<value>com/myEdition/bean/Contenttype.hbm.xml</value> -->
<value>com/myEdition/bean/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="transactionInterceptor"  class="org.springframework.transaction.interceptor">
<!--事务拦截器BEAN需要依赖注入一个事物管理器 -->
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<!-- 定义事物传播属性 -->
<props>
<prop key="delete*"> propagation_REQUIRED</prop>
<prop key="*"> propagation_REQUIRED</prop>
</props>
</property>
</bean>

<bean class=