声明式事务 AOP中织入

<!--配置声明式事务-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <constructor-arg ref="dataSource" /> </bean>
<!--结合AOP实现事务的织入-->
<!--配置事务通知-->
<tx:advice id="txAdvice" transaction-manager="
transactionManager">
<!--给哪些方法配置事务-->
<!--配置事务的传播特性 new propagation =-->
<tx:attributes>
  <tx:method name="add"
propagation="REQUIRED"/>
  <tx:method name="delete" propagation="REQUIRED"/>
  <tx:method name="update" propagation="REQUIRED"/>
  <tx:method name="query" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--aop 配置事务切入-->
<aop:config>
<!--切入点 在什么地方切入-->
  <aop:pointcut id="txPointCut" expression="execution(* com.gai.mapper.*.*(..))
"/>
<!--执行环绕切入-->
  <aop:advisor advice-ref="
txAdvice" pointcut-ref="txPointCut"/>
</aop:config>
 ==================AOP的自定义切面=================
<bean id="diy" class="com.wjw.diy.DiyPoint">
<aop:config>
<!--自定义切面 ref引用类-->
<aop:aspect ref="diy">
<!--切入点-->
<aop:pointcut id="point" expression="execution(* com.gai.service.*.*(..))"/>
<!--通知-->
<aop:before method="before" pointcut-ref="point"/>
<aop:before method="after" pointcut-ref="point"/>
</aop:aspect>
</aop:config>
posted @ 2021-07-20 20:28  蔚然长空  阅读(67)  评论(0编辑  收藏  举报