spring 声明式 rollback-for 的示例?
想要 Spring AOP 中的声明式事务管理示例......
实际上在这里
<aop:config>
<aop:advisor advice-ref="addAdvice" pointcut="execution(* com.DAO.*.*(..))"/>
</aop:config>
<tx:advice id="addAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" rollback-for="" />
</tx:attributes>
</tx:advice>
所以这里我想写的实际上是 rollback-for="" ,有什么方法或其他方法吗? 如果方法那么该方法将放在哪里?
want declarative transactional management example in spring aop........
Actually Here
<aop:config>
<aop:advisor advice-ref="addAdvice" pointcut="execution(* com.DAO.*.*(..))"/>
</aop:config>
<tx:advice id="addAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" rollback-for="" />
</tx:attributes>
</tx:advice>
So here what i want to write actually rollback-for="" , is there any method or any else?
and if method then where will it that method put?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
rollback-for
中指定异常的名称。例如,如果您想回滚your.pkg.NoProductInStockException
,您可以这样写:如果事务遇到与指定匹配的异常,这将使事务回滚。如果抛出不匹配的异常,则会将其传播到服务的调用者或包装到
TransactionRolledBackException
交易文档解释:
in
rollback-for
you specify the name of the exception. For example if you you want to rollback foryour.pkg.NoProductInStockException
, you writeThis will make the transaction be rolled back if it encounters an exception that matches the specified. If an exception is thrown that does not match, it is propagated to the caller of the service or wrapped into a
TransactionRolledBackException
The transaction documentation explains:
默认情况下,对于未经检查的异常不需要执行此操作。如果在方法内抛出未经检查的异常,则必须使用 rollback-for 属性。您可以使用正则表达式样式,例如:*InStockException
By default, there should be no need to do this for unchecked exceptions. If you throw an unchecked exception inside the method then you have to use the rollback-for attribute. You can use regular expression style, e.g.: *InStockException