zoukankan      html  css  js  c++  java
  • xml实现AOP

    1.使用<aop:config></aop:config>

    2.首先我们需要配置<aop:aspect></aop:aspect>,就是配置切面

      2.1首先配置切面的id,也就是切面叫什么名称,我们起名字为id="myLogAspect"

      2.2我们的切面是由哪一个类来做的,ref="logAspect",ref属性值是spring所管理的类(bean)

    3.配置pointcut,下面需要配置,我们要在哪一些类里面加入这些操作。或者说在那些类里面加入切面,id=""指明我们是在哪些类中加入,expression

      3.1<aop:pointcut id="logPointCut" expression="execution(* org.zttc.itat.spring.dao.*.add*(..))||

                                                                              execution(* org.zttc.itat.spring.dao.*.delete*(..))||

                                                                              execution(* org.zttc.itat.spring.dao.*.update*(..))" />

    4.配置before,method=""指明,我们要调用的是切面(切面是ref="logAspect",前面已经配置过了)里面的哪一个方法 ,point-ref=""表明我们要引入哪一个PointCut(id="logPointCut",前面也已经配置过了),也就是说我们的logStart方法会在pointcut中配置的那些类中的那些方法中加入。

      4.1<aop:before method="logStart" point-ref="logPointCut">

      4.2<aop:before method="logEnd" point-ref="logPointCut">

      4.3<aop:before method="logAround" point-ref="logPointCut">

    注解和xml哪个方便一些?

      使用注解的时候,我们需要为每一个method(before,after,around)都配置exexution,而使用xml我们只需要配置一次就可以了,从而xml更方便

  • 相关阅读:
    mysql 设置自增主键id的起始值
    一文搞定MySQL的事务和隔离级别
    SpringBoot2.0整合Redis
    Redis Cluster搭建高可用Redis服务器集群
    为什么单线程的Redis这么快?
    Spring Boot使用AOP在控制台打印请求、响应信息
    Spring boot集成spring session实现session共享
    SpringBoot项目在IntelliJ IDEA中实现热部署
    Spring Boot入门-快速搭建web项目
    一篇文章搞定SpringMVC参数绑定
  • 原文地址:https://www.cnblogs.com/mrxiaohe/p/5568509.html
Copyright © 2011-2022 走看看