@Resource private TransactionTemplate transactionTemplate; @Override public Object getTest() { Student student = new Student(); student.setAge(1); student.setName("11"); Object ob = transactionTemplate.execute(new TransactionCallback<Object>() { @Override public Object doInTransaction(TransactionStatus transactionStatus) { studentDao.insert(student); transactionStatus.setRollbackOnly(); return "执行完毕"; } }); return ob; }