Understand a few concepts before you learn spring's things management
1 What is a thing: a transaction is a series of actions that are treated as a separate unit of work. These actions are either complete or not working.
Examples: For example, bank transfer, a account transfer (200) to the B account, the action involved is a account balance reduction 200,b account balance increased by 200, the two actions as a work unit, or two actions to complete together, or two actions are not
2 What is the function of the thing: there are four characteristics, namely: atomicity (that is, multiple actions make up an atomic operation, either done together or not together)
Consistency (that is, when things are done, data and resources remain consistent)
Isolation (many transactions can handle the same data at the same time, so everything should be isolated from other transactions to prevent data corruption)
Persistence (Once a transaction is complete, its results should not be affected, no matter what system error occurs.) Typically, the result of a transaction is written to persistent memory)
Things to manage in spring use the steps:
* Steps to work with transactions:
* 1 Configure the transaction manager first (each data source spring has a corresponding transaction manager) (because the data source manager is managing the data source, you want to add the data source properties)
<id= "TransactionManager" class= " Org.springframework.jdbc.datasource.DataSourceTransactionManager "> < name = "DataSource" ref = "DataSource" ></ Property > </ Bean >
* 2 Enable transaction annotations
<!--- <Transaction-manager = " TransactionManager "/>
* 3 Use @transactional in front of the method that needs to be managed, which puts the method into the transaction manager for Management
@Transactional @Override publicvoid Purchase (string Username, String ISBN) { // 1. The unit price of the book is bookshopdao.findbookpricebyisbn (ISBN); // 2. Updated inventory Bookshopdao.updatebookstock (ISBN); // 3. Update the user balance bookshopdao.updateuseraccount (username, price); }
* 4 Why can't I use it in the test class????
The things management----HelloWorld in spring