Java – how do I get a spring transaction manager instance?

I use annotations to mark the methods that should be executed in a transaction

However, there is one place where I need to manually execute the transaction manager Rollback() without comments How do I get the transactionmanager object?

Solution

If you want to roll back the current transaction, you can use

TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

Note that it does not roll back the transaction immediately – it sets the rollback only state, so the transaction will be rolled back during an attempt to commit

Otherwise, if you need programmed transaction cancellation, you can use the transaction template, as described in 10.6 programmatic transaction management

You can also get an instance of platformtransactionmanager, but because transactiontemplate is the recommended method for programmatic transaction removal, it is not widely used

You can also see:

> 10. Transaction Management

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>