基于注解的AOP控制事务
1.拷贝上一次代码
2.applicationContext.xml
<tx:annotation-driven transaction-manager="transactionManager"/>
3.service
@Service
@Transactional(readOnly=true,propagation= Propagation.SUPPORTS)
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
public void updateUser(String source, String target, Float money) {
userMapper.updateUserOfSub(source, money);
int a = 6/0;
userMapper.updateUserOfAdd(target, money);
}
}
4.测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class ServiceTest {
@Autowired
private UserService userService;
@Test
public void testUpdate(){
userService.updateUser("张三丰","宋远桥",1F);
}
}