配置注解
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean>
创建事务bean,配置数据源属性
<tx:annotation-driven transaction-manager="transactionManager" />
事务注解驱动
声明式事务
@Transactional public void hasTranInsertData() { Book book = new Book(); book.setIsbn("0002"); book.setBookName("java编程思想"); book.setPrice(79); this.bookMapper.insertSelective(book); int i = 1 / 0; }
public void notHasTranInsertData() { Book book = new Book(); book.setIsbn("0003"); book.setBookName("算法导论"); book.setPrice(109); this.bookMapper.insertSelective(book); int i = 1 / 0; }
以上可以看出上