spring tx事务
spring 注解事务
jdbc.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/imagedb
jdbc.username=admin
jdbc.password=
imageDatabase.lobHandler=defaultLobHandler
??? <context:property-placeholder location="jdbc.properties"/>
??? <bean id="dataSource" destroy-method="close">
??? ??? <property name="driverClass" value="${jdbc.driverClassName}"/>
??? ??? <property name="jdbcUrl" value="${jdbc.url}"/>
??? ??? <property name="user" value="${jdbc.username}"/>
??? ??? <property name="password" value="${jdbc.password}"/>
??? </bean>
??? <bean id="transactionManager" ref="dataSource"/>
??? </bean>
??? <bean id="imageDatabase" ref="dataSource"/>
??? ??? ?
??? </bean>
<!-- 使用注解spring事务 -->
??? <tx:annotation-driven transaction-manager="transactionManager"/>
spring 默认捕获的异常是运行时异常
??? @Transactional? ??? ??? ??? //声明一个事务
??? @Transactional(rollbackFor=Exception.class) ??? ??? //表示就是Exception异常也要回滚事务
??? @Transactional(noRollbackFor=RuntimeException.class) ??? //表示就是运行时异常也不回滚事务
??? @Transactional(propagation=Propagation.NOT_SUPPORTED); ??? ?//声明方法不需要事务
??? xml配置事务
<aop:config>
??? <aop:pointcut? expression="'execution(* com.xyz.myapp.service.*.*(..))" id="pointcut"/>
??? ??? ??? <aop:advisor advice-ref="txadvice" pointcut-ref="pointcut"/>
??? </aop:config>
??? <tx:advice id="txadvice" transaction-manager="transactionManager">
??? ??? ??? <tx:attributes name="get" read-only="true" propagation="NOT_SUPPORTED"/>
??? ??? ??? <tx:attributes name="*" />
??? </tx:advice>
?? 做个大概的记录吧,主要还是spring帮助文档