源码注释
源码说,创建一个新事务,如果已存在一个事务,会将上层的事务挂起(暂停),意思就是你玩你的,我玩我的。
/**
* Create a new transaction, suspending the current transaction if one exists.
* Analogous to the EJB transaction attribute of the same name.
* <p><b>NOTE:</b> Actual transaction suspension will not work out-of-the-box
* on all transaction managers. This in particular applies to
* {@link org.springframework.transaction.jta.JtaTransactionManager},
* which requires the {@code jakarta.transaction.TransactionManager} to be
* made available it to it (which is server-specific in standard Jakarta EE).
* <p>A {@code PROPAGATION_REQUIRES_NEW} scope always defines its own
* transaction synchronizations. Existing synchronizations will be suspended
* and resumed appropriately.
* @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager
*/
int PROPAGATION_REQUIRES_NEW = 3;
测试环境
jdk17+mysql8+spring5.2
controller
定义一个controller,就为了方便调用service
@RestController
@RequestMapping("/api/test")
@Api(value = "测试", tags = "测试")
class Stu