spring aop学习笔记

时间:2019-09-25
本文章向大家介绍spring aop学习笔记,主要包括spring aop学习笔记使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

依赖:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
        
</beans>

spring中基于XML的AOP配置步骤:

1、把通知Bean交给spring来管理

2、使用aop:config标签表明开始AOP的配置

3、使用aop:aspect标签表明配置切面

    id属性:给切面提供一个唯一标识

    ref属性:指定通知类bean的id

4、在aop:aspect标签内部使用对应标签配置通知类型

    aop:before,表示配置前置通知。

      method属性:用于指定通知类中哪个方法是前置通知。

      pointcut属性:用于指定切入点表达式。表达式含义:对业务层哪些方法增强。

    切入点表达式写法:

      关键字:execution(表达式)

      表达式:

        访问修饰符  返回值  包名.包名...类名.方法名(参数列表)

      列如:public  void  com.lin.service.AccountServiceImpl.save()

原文地址:https://www.cnblogs.com/linyaoguo/p/11583259.html