SpringBoot事务管理器

一、配置启动器

package com.mingde;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication		//启动Spring应用
@EnableTransactionManagement  // 启注解事务管理,等同于xml配置方式的 <tx:annotation-driven />
public class SpringBootDemo {

	public static void main(String[] args) {
		SpringApplication.run(SpringBootDemo.class, args);
	}
	
}

二、在servlet类中配置事务管理器

package com.mingde.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mingde.dao.StudentDao;
import com.mingde.po.Student;
import com.mingde.services.StudentService;


@Service
public class StudentServiceImpl implements StudentService {

	@Autowired
	private StudentDao studentDao;
	
	@Override
	//@Transactional  只这样写默认是只读,下面的写法是用于增删改
	@Transactional(propagation=Propagation.REQUIRED)	//必须事务,错误时事务回滚
	public List<Student> findAll() throws Exception {
		return (List<Student>) studentDao.findAll();
	}
	
	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值