• Day 91


    _Spring技术–AOP–案例分析

    1. 思路分析

      • 导入坐标(pom.xml)
      • 制作连接点方法(原始操作,Dao接口与实现类)
      • 制作共性功能(通知类与通知)
      • 定义切入点
      • 绑定切入点与通知的关系(切面)
    2. 整体架构如图所示在这里插入图片描述

    3. 首先在pom.xml文件夹中导入aspectjweaver包:在这里插入图片描述

    4. 首先来看业务层的实现类,之中共有3个方法,注意:在updatePoint()方法中是没有打印系统时间这个方法体的在这里插入图片描述

      我们需要做的就是在不修改PersonServiceImpl的情况下在运行updatePoint() 的时候打印系统的时间

    5. 在aop包下创建AOP的配置类:在这里插入图片描述

    6. 在SpringConfig中做spring的配置:在这里插入图片描述

    7. 最后在test文件中做方法测试:

      • 在这里插入图片描述

      • package com.Alvis.servicetest;
        
        import com.Alvis.config.SpringConfig;
        import com.Alvis.service.PersonService;
        import org.junit.Test;
        import org.junit.runner.RunWith;
        import org.springframework.context.ApplicationContext;
        import org.springframework.context.annotation.AnnotationConfigApplicationContext;
        import org.springframework.test.context.ContextConfiguration;
        import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
        
        
        // 设定类运行器
        @RunWith(SpringJUnit4ClassRunner.class)
        @ContextConfiguration(classes = SpringConfig.class)
        
        public class ServiceTest {
            @Test
            public void App_01() {
                ApplicationContext apx = new AnnotationConfigApplicationContext(SpringConfig.class);
                PersonService personService = apx.getBean(PersonService.class);
                personService.run();
            }
        
            @Test
            public void App_02() {
                ApplicationContext apx = new AnnotationConfigApplicationContext(SpringConfig.class);
                PersonService personService = apx.getBean(PersonService.class);
                personService.updatePoint();
            }
        }
        ================================================
        824, 2022 12:24:35 上午 org.springframework.test.context.support.AbstractTestContextBootstrapper getDefaultTestExecutionListenerClassNames
        信息: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
        824, 2022 12:24:35 上午 org.springframework.test.context.support.AbstractTestContextBootstrapper getTestExecutionListeners
        信息: Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@7714e963, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@20ce78ec, org.springframework.test.context.support.DirtiesContextTestExecutionListener@393671df, org.springframework.test.context.event.EventPublishingTestExecutionListener@56620197]
        
        
        1661271876399
        update Point...and add currentTime
        
        进程已结束,退出代码0
        
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        • 12
        • 13
        • 14
        • 15
        • 16
        • 17
        • 18
        • 19
        • 20
        • 21
        • 22
        • 23
        • 24
        • 25
        • 26
        • 27
        • 28
        • 29
        • 30
        • 31
        • 32
        • 33
        • 34
        • 35
        • 36
        • 37
        • 38
        • 39
        • 40
        • 41
        • 42
        • 43
  • 相关阅读:
    【Netty】Netty 编解码器(十四)
    python垃圾自动清理机制
    MySQL 中读写分离数据延迟
    漏洞复现-CVE-2022-1388命令执行F5 BIG-IP iControl REST
    AI秘籍:助您提升办公和学习效率
    spark报错:Cannot overwrite a path that is also being read from.
    冬天这么冷,到底要不要坚持送孩子入托?
    Flutter 3.3 现已发布
    【LeetCode热题100】--153.寻找旋转排序数组中的最小值
    C++语言之组合、聚合类间关系、访问权限、多模块作业详解
  • 原文地址:https://blog.csdn.net/ALVIS_108/article/details/126495617