`
hiskyrisa
  • 浏览: 36155 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

Exception:Spring3.2 AOP 事务管理

阅读更多

Spring的配置文件中,事务配置如下:

<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true" />
			<tx:method name="add*" propagation="REQUIRED"/> 
			<tx:method name="delete*" propagation="REQUIRED"/> 
			<tx:method name="update*" propagation="REQUIRED"/>
			<!--<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/> 
				<tx:method name="preCommitTaskitem" propagation="NEVER"/> <tx:method name="preStartProcess" 
				propagation="NEVER"/> <tx:method name="isDisplayPostNode" propagation="NEVER"/> -->
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<aop:pointcut id="allMethod" expression="execution(* com.student.service.*.*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="allMethod" />
	</aop:config>

 

其中更新等操作必须开启事务,若抛出Exception,则要求事务回滚。需要注意以下两点:

1、在service中,如果Exception被try、catch处理后,则Aop将不会再进行回滚处理。

2、service中的异常不能直接抛出去,Spring的Aop不识别java.lang.Exception,需要在service中重新抛出runtineException才可触发事务回滚。代码如下:

@Service
public class StudentService {
	@Autowired
	StudentDao studentDao;
	
	public Student add(Student student) throws RuntimeException {
		studentDao.add(student);
		studentDao.add(student);
		throw new RuntimeException("1");
	}
}

 

0
1
分享到:
评论

相关推荐

    spring-aop-5.0.10.RELEASE-API文档-中文版.zip

    赠送jar包:spring-aop-5.0.10.RELEASE.jar; 赠送原API文档:spring-aop-5.0.10.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.0.10.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.0.10.RELEASE....

    Spring3.2 AOP extra jar

    Spring3.2 版本中已不再提供第三放jar包,而在实际“AOP”应用中需要引入其他的jar包;此为,已知的jar包(最新版本)。

    spring-aop-5.2.0.RELEASE-API文档-中文版.zip

    赠送jar包:spring-aop-5.2.0.RELEASE.jar; 赠送原API文档:spring-aop-5.2.0.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.2.0.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.2.0.RELEASE.pom;...

    spring-aop-5.0.8.RELEASE-API文档-中英对照版.zip

    赠送jar包:spring-aop-5.0.8.RELEASE.jar; 赠送原API文档:spring-aop-5.0.8.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.0.8.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.0.8.RELEASE.pom;...

    spring-aop-5.3.10-API文档-中文版.zip

    赠送jar包:spring-aop-5.3.10.jar; 赠送原API文档:spring-aop-5.3.10-javadoc.jar; 赠送源代码:spring-aop-5.3.10-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.3.10.pom; 包含翻译后的API文档:spring...

    spring-aop-5.3.12-API文档-中英对照版.zip

    赠送jar包:spring-aop-5.3.12.jar; 赠送原API文档:spring-aop-5.3.12-javadoc.jar; 赠送源代码:spring-aop-5.3.12-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.3.12.pom; 包含翻译后的API文档:spring...

    spring-aop-5.3.15-API文档-中英对照版.zip

    赠送jar包:spring-aop-5.3.15.jar; 赠送原API文档:spring-aop-5.3.15-javadoc.jar; 赠送源代码:spring-aop-5.3.15-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.3.15.pom; 包含翻译后的API文档:spring...

    spring-aop-5.1.3.RELEASE-API文档-中英对照版.zip

    赠送jar包:spring-aop-5.1.3.RELEASE.jar; 赠送原API文档:spring-aop-5.1.3.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.1.3.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.1.3.RELEASE.pom;...

    spring-aop-5.3.15-API文档-中文版.zip

    赠送jar包:spring-aop-5.3.15.jar; 赠送原API文档:spring-aop-5.3.15-javadoc.jar; 赠送源代码:spring-aop-5.3.15-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.3.15.pom; 包含翻译后的API文档:spring...

    spring-aop-4.2.2.RELEASE-API文档-中文版.zip

    赠送jar包:spring-aop-4.2.2.RELEASE.jar; 赠送原API文档:spring-aop-4.2.2.RELEASE-javadoc.jar; 赠送源代码:spring-aop-4.2.2.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-4.2.2.RELEASE.pom;...

    spring-aop-4.3.20.RELEASE-API文档-中英对照版.zip

    赠送jar包:spring-aop-4.3.20.RELEASE.jar 赠送原API文档:spring-aop-4.3.20.RELEASE-javadoc.jar 赠送源代码:spring-aop-4.3.20.RELEASE-sources.jar 包含翻译后的API文档:spring-aop-4.3.20.RELEASE-...

    spring-aop-5.3.7-API文档-中文版.zip

    赠送jar包:spring-aop-5.3.7.jar; 赠送原API文档:spring-aop-5.3.7-javadoc.jar; 赠送源代码:spring-aop-5.3.7-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.3.7.pom; 包含翻译后的API文档:spring-aop...

    Spring源代码解析(五):Spring_AOP获取Proxy.doc

    Spring源代码解析(五):Spring_AOP获取Proxy.doc

    spring-aop-5.3.10-API文档-中英对照版.zip

    赠送jar包:spring-aop-5.3.10.jar;赠送原API文档:spring-aop-5.3.10-javadoc.jar;赠送源代码:spring-aop-5.3.10-sources.jar;赠送Maven依赖信息文件:spring-aop-5.3.10.pom;包含翻译后的API文档:spring-aop...

    spring-aop-5.2.15.RELEASE-API文档-中文版.zip

    赠送jar包:spring-aop-5.2.15.RELEASE.jar; 赠送原API文档:spring-aop-5.2.15.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.2.15.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.2.15.RELEASE....

    spring-aop.jar各个版本

    spring-aop-1.1.1.jar spring-aop-1.2.6.jar spring-aop-1.2.9.jar spring-aop-2.0.2.jar spring-aop-2.0.6.jar spring-aop-2.0.7.jar spring-aop-2.0.8.jar spring-aop-2.0.jar spring-aop-2.5.1.jar spring-aop-...

    spring-aop-5.0.5.RELEASE-API文档-中文版.zip

    赠送jar包:spring-aop-5.0.5.RELEASE.jar; 赠送原API文档:spring-aop-5.0.5.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.0.5.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.0.5.RELEASE.pom;...

    spring-aop-4.3.12.RELEASE-API文档-中文版.zip

    赠送jar包:spring-aop-4.3.12.RELEASE.jar; 赠送原API文档:spring-aop-4.3.12.RELEASE-javadoc.jar; 赠送源代码:spring-aop-4.3.12.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-4.3.12.RELEASE....

    spring-aop-5.0.8.RELEASE-API文档-中文版.zip

    赠送jar包:spring-aop-5.0.8.RELEASE.jar; 赠送原API文档:spring-aop-5.0.8.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.0.8.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.0.8.RELEASE.pom;...

    spring-aop-5.1.3.RELEASE-API文档-中文版.zip

    赠送jar包:spring-aop-5.1.3.RELEASE.jar; 赠送原API文档:spring-aop-5.1.3.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.1.3.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.1.3.RELEASE.pom;...

Global site tag (gtag.js) - Google Analytics