SpringAOP事务—AspectJ配置

久未见 提交于 2019-11-27 22:07:29

SpringAOP配置:
必须代理类
每个Service必须注册一个代理类
AOP-XML配置
SpringAOP注解:
每个Service类的每个方法都有添加注解
AOP-注解配置
AspectJ注解配置:一般推荐使用这种
在基于之前的jar包下新添
apsetj-weaver.jar spring-aspectj.jar
xml配置

<!-- 配置事务管理器 -->
	<bean id="transactionManager" 
	class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	<property name="dataSource" ref="dataSource"/>
	</bean>
	<!--配置事务事务通知,引入tx约束  -->
	<tx:advice id="txadvice" transaction-manager="transactionManager">
	<!--配置事务属性  -->
	<tx:attributes>
	<tx:method name="open*" isolation="DEFAULT" propagation="REQUIRED"/>
	<tx:method name="buy*" isolation="DEFAULT" propagation="REQUIRED"/>
	</tx:attributes>
	</tx:advice>
	
	<aop:config>
	<!--配置切入点,配置切入点表达式  -->
	<aop:pointcut expression="execution(* *..service.*.*(..))" id="txpointcut"/>
	<!-- 配置事务 -->
	<aop:advisor advice-ref="txadvice" pointcut-ref="txpointcut"/>
	</aop:config>

tx:method 当中表示通配符,name可以写方法全名或者利用表达都可以

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!