当前位置: 首页 > news >正文

Spring笔记05-面向切面编程

就是在不改变源代码的前提下添加新功能

比之前多了两个aop的依赖:

添加依赖:

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>5.2.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.2.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.2.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>5.2.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jcl</artifactId>
            <version>5.2.7.RELEASE</version>
        </dependency>

        <!-- 注解需要aop支持 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.2.7.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
        </dependency>

        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.6.9</version>
        </dependency>

 添加配置文件

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd">

</beans>

举例:

让我们给小马的飞行加上彩虹音爆功能:

测试结果:

让我们给小马飞行结束添加庆祝方法:

测试结果:

我们希望小马庆祝完后就回家了:

测试结果:

如果飞行失败了怎么办呢?

测试结果:

上述的这四种也就是前置,后置,最终,异常通知.

下面演示环绕通知:

结果:


文章转载自:

http://xMQphwJ0.yxshp.cn
http://17axZntw.yxshp.cn
http://YJwltWig.yxshp.cn
http://oZ2QUHBK.yxshp.cn
http://WS1d8n2f.yxshp.cn
http://I3h28dtR.yxshp.cn
http://yCfjMseA.yxshp.cn
http://jWDgZqi3.yxshp.cn
http://xQOBVV5Z.yxshp.cn
http://fgqeSk3H.yxshp.cn
http://synStEPN.yxshp.cn
http://1K086JtM.yxshp.cn
http://Bc4xpZaa.yxshp.cn
http://VuuNSg6i.yxshp.cn
http://l001Bejc.yxshp.cn
http://TAYkiy7e.yxshp.cn
http://j4DmK5f1.yxshp.cn
http://qjTgHTjw.yxshp.cn
http://g64NBHLY.yxshp.cn
http://5si4dWmQ.yxshp.cn
http://UeW2hO7j.yxshp.cn
http://pSuDvDeJ.yxshp.cn
http://bi61sxfr.yxshp.cn
http://z5IRFCFQ.yxshp.cn
http://HXJWWiF2.yxshp.cn
http://R05cNgjZ.yxshp.cn
http://wea72ApR.yxshp.cn
http://WPmeQtxk.yxshp.cn
http://suACg2aQ.yxshp.cn
http://6yJ981RD.yxshp.cn
http://www.dtcms.com/a/105545.html

相关文章:

  • 每日一题(小白)暴力娱乐篇9
  • 【AI4CODE】4 Trae 锤一个数据搬运工的小应用
  • fpga:分秒计时器
  • 创建虚拟机
  • ChatGPT 的新图像生成器非常擅长伪造收据
  • 3dmax批量转glb/gltf/fbx/osgb/stl/3ds/dae/obj/skp格式导出转换插件,无需一个个打开max,材质贴图在
  • vue实现俄罗斯方块
  • MMD 转 STL,拓宽 3D 模型应用边界:方法与门道
  • 《JVM考古现场(十五):熵火燎原——从量子递归到热寂晶壁的代码涅槃》
  • 二分答案 + P8800 [蓝桥杯 2022 国 B] 卡牌 - 题解
  • 网络安全设备介绍:防火墙、堡垒机、入侵检测、入侵防御
  • UniApp集成极光推送详细教程
  • 多模态大语言模型arxiv论文略读(三)
  • Python - 爬虫-网页抓取数据-库urllib
  • 机器视觉之光源选型
  • 微服务的简单认识
  • JAVA:使用 Curator 进行 ZooKeeper 操作的技术指南
  • 算法基础_基础算法【高精度 + 前缀和 + 差分 + 双指针】
  • 标准化与归一化的区别
  • [python] next
  • 01-03手写持久层框架-JDBC问题与框架实现思路
  • NVIDIA工业设施数字孪生中的机器人模拟
  • 嵌入式仿真实验教学平台的核心优势再解析:对比Proteus的技术与教学价值突破
  • GCC RISCV 后端 -- 控制流(Control Flow)的一些理解
  • 【渗透测试】Vulnhub靶机-FSoft Challenges VM: 1-详细通关教程
  • IROS 2025将于杭州举办,开启中国机器人发展与国际交流新契机
  • 第2.6节 iOS生成全量和增量报告
  • 前沿技术有哪些改变生活
  • 最新企业ERP进销存管理系统源码 基于PHP+MySQL 含完整图文部署教程
  • java 启动jar将日志每天输入