关于spring的AOP使用
来源:互联网 发布:小企业财务会计软件 编辑:程序博客网 时间:2024/04/30 09:26
目前项目中用的比较多的是@AspectJ注解的切面和XML配置的AOP
表述:
最近这个项目用的是XML配置的AOP
配置一个<aop:config>跟节点,下面配置一个advisor或者aspect,里面再配置一个pointcut的正则表示执行的地点和advice什么时候执行什么事。
概念陈述:
1.通知(advice),定义了什么时候,做什么事。
2.切点(pointcut),定义了在什么地点。
3.通知者 (advisor),一个通知者包含一个切点和一个通知者
4.切面 (aspect ),一个切面可以包含多个切点和通知者
实例1:利用AOP切面控制事物,通知者 (advisor),一个通知者包含一个切点和一个通知者
<aop:config>
<aop:pointcut id="jdbcDataAccessOperation" expression="execution(* com.lujun.imw.common.service.*.*(..)) ||
execution(* com.lujun.imw.mgs.common.service.*.*(..)) ||
execution(* com.lujun.imw.imp.common.service.*.*(..)) ||
execution(* com.lujun.imw.mmc.service.*.*(..))" /> <!--切点,配置在什么地点-->
<aop:advisor advice-ref="jdbcTxAdvice" pointcut-ref="jdbcDataAccessOperation" /> <!--通知者,由一个通知(advice)和一个切点(pointcut)组成-->
</aop:config>
<!--通知(advice)-->
<tx:advice id="jdbcTxAdvice" transaction-manager="jdbcTxManager"> <!--做什么事:事物控制-->
<tx:attributes>
<tx:method name="save*" rollback-for="Exception" /> <!--什么时候:增删改-->
<tx:method name="insert*" rollback-for="Exception" />
<tx:method name="update*" rollback-for="Exception" />
<tx:method name="delete*" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
spring在aop的命名空间里面还提供了其他的配置元素:
<aop:advisor> 定义一个AOP通知者
<aop:after> 后通知
<aop:after-returning> 返回后通知
<aop:after-throwing> 抛出后通知
<aop:around> 周围通知
<aop:aspect>定义一个切面
<aop:before>前通知
<aop:config>顶级配置元素,类似于<beans>这种东西
<aop:pointcut>定义一个切点
实例2:切面 (aspect ),一个切面可以包含多个切点和通知者
<aop:config>
<aop:aspect ref="sleepHelper">
<aop:before method="beforeSleep" pointcut="execution(* *.sleep(..))"/> //<aop:before>这个节点本身就是一个通知,在before(什么时候) sleep方法(切点)的时候(什么地方),执行beforeSleep方法(做什么事)
<aop:after method="afterSleep" pointcut="execution(* *.sleep(..))"/>
</aop:aspect>
</aop:config>
- 关于spring的AOP使用
- 关于 spring aop execution 属性的使用
- Spring AOP的使用
- Spring AOP的使用
- spring-aop的使用
- Spring AOP的使用
- SPRING AOP的使用
- 初学spring 关于IOC与AOP 使用的设计模式
- 初学spring 关于IOC与AOP 使用的设计模式
- 关于Spring aop框架使用的jar包下载
- 初学spring 关于IOC与AOP 使用的设计模式
- spring的aop的使用
- spring与AOP的使用
- spring的Aop使用问题
- Spring中AOP的使用
- Spring aop 通知的使用
- Spring的AOP使用实例
- spring boot-aop的使用
- android中的byte数组转换
- Jquery 时间类型格式化
- php.ini 常用配置
- <C++ 实现设计模式> 观察者模式
- iOS禁止屏幕锁定
- 关于spring的AOP使用
- CLR via C# FOURTH EDITION(三)
- 国内从事编译相关研究和开发的单位列表(截至2012-7-4)
- 数据结构学习之-------树 Trees on the level HDU 1622
- struts1和struts2的区别
- 静态构造的学习
- vnc的启动与停止glassfish在linux下命令行启动与停止
- JSP C标签 示例 待续
- Android底层开发之红外遥控驱动移植