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

(38)基于XML配置方式的AOP(了解)

第一步:编写目标类

packagecom.powernode.spring6.service;// 目标类publicclassVipService{publicvoidadd(){System.out.println("保存vip信息。");}}

第二步:编写切面类,并且编写通知

packagecom.powernode.spring6.service;importorg.aspectj.lang.ProceedingJoinPoint;// 负责计时的切面类publicclassTimerAspect{publicvoidtime(ProceedingJoinPointproceedingJoinPoint)throwsThrowable{longbegin=System.currentTimeMillis();//执行目标proceedingJoinPoint.proceed();longend=System.currentTimeMillis();System.out.println("耗时"+(end-begin)+"毫秒");}}

第三步:编写spring配置文件

<?xml version="1.0" encoding="UTF-8"?><beansxmlns="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 http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><!--纳入spring bean管理--><beanid="vipService"class="com.powernode.spring6.service.VipService"/><beanid="timerAspect"class="com.powernode.spring6.service.TimerAspect"/><!--aop配置--><aop:config><!--切点表达式--><aop:pointcutid="p"expression="execution(* com.powernode.spring6.service.VipService.*(..))"/><!--切面--><aop:aspectref="timerAspect"><!--切面=通知 + 切点--><aop:aroundmethod="time"pointcut-ref="p"/></aop:aspect></aop:config></beans>

测试程序:

packagecom.powernode.spring6.test;importcom.powernode.spring6.service.VipService;importorg.junit.Test;importorg.springframework.context.ApplicationContext;importorg.springframework.context.support.ClassPathXmlApplicationContext;publicclassAOPTest3{@TestpublicvoidtestAOPXml(){ApplicationContextapplicationContext=newClassPathXmlApplicationContext("spring-aop-xml.xml");VipServicevipService=applicationContext.getBean("vipService",VipService.class);vipService.add();}}
http://www.jsqmd.com/news/154264/

相关文章:

  • 扩域技术
  • 2025卫生间瓷砖品牌TOP5权威推荐:深度测评指南 - 工业推荐榜
  • YOLOv10来了!新架构带来的算力需求变化分析
  • 阀门生产厂、品牌供应商与服务商家的优质之选——天津中阀科技 - 工业推荐榜
  • YOLO模型太大无法部署?教你用GPU+TensorRT极致压缩
  • (39)AOP的实际案例
  • 2025年郑州美业培训学校排行榜,新测评精选美业教育机构推荐 - 工业品牌热点
  • (41)事务属性(建议在数据库深入学习)
  • YOLO目标检测模型训练太慢?试试我们的高性能GPU套餐
  • YOLO训练成本太高?我们送你免费GPU token体验包
  • (42)事务的两种开发模式
  • 生成式AI移动应用测试工程方法论
  • 2025白刚玉定制口碑前十强,你选对了吗?磨料/金刚砂/碳化硅/白刚玉/不锈钢灰/精密铸造砂/棕刚玉/铬刚玉/黑碳化硅白刚玉厂家有哪些 - 品牌推荐师
  • YOLO + Triton推理服务器:构建高并发检测服务
  • 2025年谁主沉浮?顶尖重型货架厂家综合评比,重型板材存放架/重型货架超强承重/重型模具货架/伸缩悬臂货架/重型货架重型货架定制厂家哪家强 - 品牌推荐师
  • Compose笔记(六十四)--LottieAnimation
  • HTTP的简介和原理 - saboyou1
  • 2025.12.28博客
  • 智能 Agent 的概念建模与系统特征分析-从传统程序到自主智能体的范式演进
  • vue 甘特图 vxe-gantt table 可视化依赖线的使用,可视化拖拽创建连接线的用法
  • Cloudflare Wrangler CLI 备忘
  • 论文阅读(十二月第四周)
  • 做不出IT毕设,我是废物吗?
  • YOLO模型支持Logstash日志处理管道
  • YOLO模型训练支持CutOut与HideAndSeek图像遮挡增强
  • 2025年三合一过滤洗涤干燥机厂家排名:哈氏合金/搪瓷设备专业制造商推荐 - mypinpai
  • 从“拔网线“看互联网大厂的安全攻防:黑灰产攻击原理与防御实战
  • Next AI Draw.io 核心实现深度分析
  • HTTP的原理 - saboyou1
  • 2025年优质尼龙拖链品牌排行榜,尼龙拖链与其他材质拖链对比优势在哪? - mypinpai