springboot transaction management

The configuration of the transaction is to add two annotations on the basis of mybatis. 1. The required annotations are  and  two 
@EnableTransactionManagement@Transactional

2. First, find your service implementation class and add @Transactional annotations. If you add it to the class, all the methods of the class will be managed by the transaction. If you add it to the method, only the method conforms to the specific transaction. Of course, we generally add to the method. Because only additions, deletions, and changes will require transactions. For example, the following method of inserting data adds a transaction: 

@Override
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor=Exception.class)
public Integer add(Cbf_jtcy t) {
    return cbf_jtcyMapper.insert(t);
}

 3. After the configuration, the spring boot startup class must open the transaction, and the annotation for opening the transaction is @EnableTransactionManagement as follows:

@SpringBootApplication
@EnableTransactionManagement
@MapperScan("microservice.qssj.mapper")//This must be added, no error will be reported, if not, @Mapper annotation can also be added to each mapper, and one more annotation needs to be filled in here, that I forgot , I've been using this annotation
public class QssjServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(QssjServiceApplication.class, args);
    }
}

 This completes the configuration of the transaction.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326120551&siteId=291194637