未分类 · 2024-11-25 0

出现 UnexpectedRollbackException: Transaction silently rolled back because it has been marked as rollback-only

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Transactional
    @Override
    public void save1() {
        StudentDO studentDO = new StudentDO("zhang1");
        StudentDO result = studentDao.save(studentDO);

        StudentService service = SpringUtils.getBean(StudentService.class);

        try {
            service.save2();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    @Transactional
    @Override
    public void save2() {
        int i = 1 / 0;
    }
}