码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Spring学习(8) AOP


    • AspectJ框架[AOP框架]
    • 使用AspectJ步骤
    • Spring中AOP概述
    • Spring中AOP相关术语

    AspectJ框架[AOP框架]

    • AspectJ是Java社区里最完善最流行的AOP框架
    • 在Spring2.0以上版本中,可以使用基于AspectJ注解或基于XML配置的AOP

    使用AspectJ步骤

    1. 添加jar包支持
           <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
                <version>5.3.18</version>
            </dependency>
            
             <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>5.1.5.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
                <version>1.9.7</version>
                <scope>compile</scope>
            </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    1. 配置文件
      • 开启组件扫描
      • 开启AspectJ注解支持
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
    
    <!--    开启组件扫描-->
        <context:component-scan base-package="com.zyh.aop"></context:component-scan>
    
    <!--    开启AspectJ注解支持-->
        <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
    
    </beans>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    1. 把MyLogging类上面添加注解
      @Component:把当前类标识为组件
      @Aspect:把当前类标识为切面类[非核心业务提取类]

    2. 把MyLogging中的方法添加通知注解
      @Before
      在这里插入图片描述

    3. 测试
      在这里插入图片描述

    Spring中AOP概述

    • AOP: Aspect-Oriented Programming 面向切面编程
      • 优势 :
        • 解决代码分散问题
        • 解决代码混乱问题
    • OOP: Object-Oriented Programming :面向对象编程

    Spring中AOP相关术语

    • ①横切关注点 :非核心业务代码,称之为横切关注点
    • ②切面(Aspect):把横切关注点提取到一个类,这个类称为切面类
    • ③通知(Advice):把横切关注点提取到类中以后,横切关注点更名为通知
    • ④目标(Target):目标对象,指的是需要被代理的对象[实现类CalcImpl]
    • ⑤代理(Proxy):代理对象可以理解为中介
    • ⑥连接点(JoinPointer):通知方法需要指定通知位置,这个位置称为连接点[通知之前]
    • ⑦切入点(pointcut):通知方法需要指定通知位置,这个位置称为切入点[通知之后]
  • 相关阅读:
    Python实操 PDF自动识别并提取Excel文件
    【深度学习】关于处理过拟合的一点心得
    Apifox --- 全套服务提升了团队效率,让研测之间充满了爱(记Apifox在工程中的实际应用)【云原生】
    卷积、填充、步长;卷积神经网络的卷积核大小、个数,卷积层数如何确定呢;深度学习如何调参;
    经典模型——ResNet
    哥斯拉加密WebShell过杀软
    ubuntu20.04 运行 lio-sam 流程记录
    谈谈我的「数字文具盒」 - 运行平台
    Discuz3.X各广告位的具体位置和效果探究
    【C++干货铺】初识模板
  • 原文地址:https://blog.csdn.net/qq_52797170/article/details/125579739
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号