1, the Spring's transaction mechanism
1.1, all data access technology has transaction processing, these technologies provide an API to open the transaction , the transaction is committed to complete operational data ( abnormal transaction rollback );
1.2, the Spring's transaction mechanism : a unified mechanism to handle transaction processing different data access technologies ;
1.3, the Spring's transaction mechanism provides a PlatformTransactionManager interface to different data access technology to use a different interface :
2, the Spring's declarative transaction
2.1, Spring declarative transaction support, namely the use of annotations @Transactional in the way that this method requires transaction support;
Annotated method when invoked , Spring open a new transaction , when no abnormal operation after the end of the method , the Spring will be submitted to the transaction ;
The annotation @Transactional located at org.springframework.transaction.annotation packet ;
@Transactional public void test(){ }
2.2, Spring provides @EnableTransactionManagement on the configuration class open declarative transaction support ;
After using @EnableTransactionManagement , the Spring container will be automatically annotated @Transactional scanning method, the class ;
3, notes transactional behavior
@Transactional defines propagation , Isolation , timeout , readOnly , rollbackFor , noRollbackFor to customize transactional behavior :
·······
4, the class level using @Transactional
4.1、@Transactional 不仅 可以用在方法上 ,还 可以使用在类上;
4.2、@Transactional 注解在类上时,整个类的所有public方法都是开启事务的;
如果 类级别、方法级别 同时使用@Transactional,类级别 会 重载方法级别;