1.导入jar包
2.导入新的约束(tx)
beans:最基本
context:读取properties配置文件
aop:配置aop
tx:配置事务通知
3.配置通知
<!-- 配置事务通知 -->
<tx:advice transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="transfer" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
</tx:attributes>
</tx:advice>
如果有上百个属性,要一一配置事务的属性很麻烦,那么通过以下方法:
设置通配符,比如包含save的方法,一律使用
isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"
4.将通知织入目标
<!-- 配置织入 -->
<aop:config>
<aop:pointcut expression="execution(*cn.service.*ServiceImpl.*(..))" id="txPc"/>
<!-- 配置切面 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPc"/>
</aop:config>
配置完成后,会自动配置的切点表达式execution(*cn.service.ServiceImpl.(…))寻找符合条件的对象,织入通知,织入通知后会根据通知的关键字来判断具体需要哪些配置的属性