1. 声明式事物配置,applicationContext.xml中需额外添加以下:
<!--xmlns:tx="http://www.springframework.org/schema/tx" 主要用于声明式事物,在导入jdbc包时,被引入-->
xmlns:tx="http://www.springframework.org/schema/tx"
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
<!--xmlns:tx="http://www.springframework.org/schema/tx" 主要用于声明式事物,在导入jdbc包时,被引入-->
<!--(jdbc)声明式事物配置-->
<!--transactionManager事物管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!--数据源设置-->
<property name="dataSource" ref="dataSource"/>
</bean>
<!--启用与之对应的注解模式-->
<tx:annotation-driven transaction-manager="transactionManager"/>
2. 在service文件夹中的,类方法中需注明:
@Transactional //声明式事物