日期:2014-05-16  浏览次数:20490 次

spring中如何做事务?(标准做法---集成jdbc)
spring中如何做事务?(标准做法---集成jdbc)
配置如下:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
	    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://127.0.0.1/spring_19_jdbc" />
		<property name="username" value="root" />
		<property name="password" value="123456" />		
	</bean> 
	
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	<tx:advice id="txAdvice" transaction-manager="transactionManager" >
		<tx:attributes>
			<tx:method  name="add*" propagation="REQUIRED" />
			<tx:method  name="update*" propagation="REQUIRED" />
			<tx:method  name="del*" propagation="REQUIRED" />
			<tx:method  name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>
	
	<aop:config>
		<aop:pointcut id="managerMethod" expression="execution(* com.cs.dao.*.*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="managerMethod" />
	</aop:config>
bean的配置:
   <bean id="userDao" class="com.cs.dao.UserDaoImpl" >
    <property name="dataSource" ref="dataSource" />    //必须要配置 因为继承自JdbcDaoSupport
    <property name="logDao"  ref="logDao" />
    <!-- 此处的userDaoIpml涉及事务处理,所以要注入logDao属性  -->
    </bean>

解析请参考事务集成hibernate的解析