zoukankan      html  css  js  c++  java
  • spring aop

    1.拦截器:

    1.1. implements MethodInterceptor,方法拦截器. 可以在指定的方法执行前后执行自己的代码.

    1.2. implements AfterReturningAdvice,方法后缀处理器,可以在指定的方法执行后执行自己的代码.

    配置如下:(1.1和1.2都一样)

    <bean id="methodCacheInterceptor" class="com.bbbb.platform.interceptor.MethodCacheInterceptor"></bean>
      <!-- 配置查找cache拦截器切入点-->
      <bean id="methodCachePointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        <property name="advice">
          <ref local="methodCacheInterceptor"/>
        </property>
        <property name="patterns">
          <list>
            <value>.*_cache.*</value>
          </list>
        </property>
       </bean>

    2.纯aop: (纯类,只需要有提供载体的处理链接点即可)

    配置如同事务,如下:

    <aop:config>
      <!-- 配置事务切面 -->
      <aop:pointcut id="serviceOperation"
      expression="execution(* com.xxxxx.*.service..*.*(..))" />
      <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />

      <!-- 配置日志切入点 -->
      <aop:aspect id="operateLogManager" ref="operateLogAdvice">
        <aop:around method="record" pointcut="(execution(* com.xxxxx.*.service..*Service.save*(..)) or
          execution(* com.xxxxx.*.service..*Service.insert*(..)) or
          execution(* com.xxxxx.*.service..*Service.add*(..)) or
          execution(* com.xxxxx.*.service..*Service.update*(..)) or
          execution(* com.xxxxx.*.service..*Service.modif*(..)) or
          execution(* com.xxxxx.*.service..*Service.change*(..)) or
          execution(* com.xxxxx.*.service..*Service.remove*(..)) or
          execution(* com.xxxxx.*.service..*Service.del*(..)) or
          execution(* com.xxxxx.*.service..*Service.edit*(..)))
          and !bean(operateLogService)
          "/><!-- .save*(..) 表示以save开头的所有方法,..Service,第一个.表示目录分隔,第二个点表示类 -->
      </aop:aspect>
    </aop:config>

  • 相关阅读:
    [转]在Ubuntu 下安装Redis 并使用init 脚本启动
    [资源]PHP使用消息队列
    [转]reids客户端 redis-cli用法
    [转]redis.conf的配置解析
    【转】微信公共号开发,提示“该公众号暂时无法提供服务,请稍后再试”,如何解决?
    [转]php 解决json_encode中文UNICODE转码问题
    [资料]Keychain 获取设备唯一
    [转]PHP 获取服务器详细信息代码
    crontab任务取消发送邮件
    [转]php返回json数据中文显示的问题
  • 原文地址:https://www.cnblogs.com/yanjunwu/p/4000278.html
Copyright © 2011-2022 走看看