Introduction
spring事务propagation(事务传播特性)配置,常用的配置项为Propagation.REQUIRED或者Propagation.REQUIRES_NEW。
Propagation.REQUIRED:如果当前有事务,则在当前事务中执行,如果没有事务,则创建一个事务执行。
Propagation.REQUIRES_NEW:无论如何创建一个新的事务执行。
这里的事务指的是数据库层面的事务(physical transaction)
如果在当前事务中,调用有@Transactional(Propagation.REQUIRED/REQUIRES_NEW)配置的方法,在该方法中触发了事务回滚条件,由于REQUIRED在当前事务中执行,所以当前事务会回滚,而REQUIRES_NEW新建一个事务,所以新建的事务会回滚,而当前事务是否回滚与此无关。
REQUIRED
@Service
public class TestServiceImpl02 implements TestService {
@Autowired
private SmsUserMapper smsUserMapper;
@Autowired
private TestService testServiceImpl01;
@Override
@Transactional(propagation=Propagation.REQUIRED)
public void test() {
SmsUser user = new SmsUser();
user.setUserAccount("baizq000");
user.setUserPwd("000000");
user.setUserStatus(0);
user.setPlatformName("xxx");
smsUserMapper.insert(user);
testServic