【问题标题】:How can I extend and add more functionality to Transaction advise of Spring?如何为 Spring 的 Transaction 建议扩展和添加更多功能?
【发布时间】:2017-04-13 19:35:59
【问题描述】:

我正在使用 Spring Transactions,并且我的服务类被注释了 @Transactional 注释。
我想在事务提交/回滚之前和之后添加一些代码而不添加新的方面,所以我想扩展 Spring 内部使用的方面并使 Spring Transaction 使用该事务建议而不是默认建议。

【问题讨论】:

标签: spring spring-transactions


【解决方案1】:

您可以考虑使用 Springs 提供的 TransactionListener。 @TransactionEventListner 采用 BEFORE_COMMIT、AFTER_COMMIT、AFTER_ROLLBACK、AFTER_COMPLETION 等选项。这表明侦听器应该何时触发事件。

Spring 为处理必须处理 post/pre txn 提交/回滚的情况提供了此功能。

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html#transaction-event

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多