news 2026/6/10 13:33:27

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

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
(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();}}
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/10 12:58:25

YOLO + GPU加速:打造工业视觉检测的黄金组合

YOLO GPU加速&#xff1a;打造工业视觉检测的黄金组合 在现代工厂的高速生产线上&#xff0c;每分钟都有成百上千个工件经过质检环节。一个微小的划痕、一次错位装配&#xff0c;都可能引发后续产品的大规模返修甚至召回。传统依靠人工目检或基于规则图像处理的方式早已不堪重…

作者头像 李华
网站建设 2026/6/7 18:05:11

YOLO开源社区最火项目TOP10,全部支持GPU加速

YOLO开源社区最火项目TOP10&#xff0c;全部支持GPU加速 在智能制造、城市大脑和自动驾驶等前沿领域&#xff0c;实时视觉感知正成为系统决策的“眼睛”。而在这双眼睛背后&#xff0c;YOLO系列模型几乎无处不在——从工厂流水线上的缺陷检测&#xff0c;到十字路口的车流统计&…

作者头像 李华
网站建设 2026/6/9 22:21:06

YOLO模型太大无法部署?教你用GPU+TensorRT极致压缩

YOLO模型太大无法部署&#xff1f;教你用GPUTensorRT极致压缩 在工业质检线上&#xff0c;每秒流过数十个零件&#xff0c;系统必须在几十毫秒内完成缺陷检测&#xff1b;在自动驾驶车辆中&#xff0c;摄像头实时捕捉道路画面&#xff0c;任何延迟都可能带来安全隐患。这些场景…

作者头像 李华
网站建设 2026/6/10 11:11:23

Next AI Draw.io 核心实现深度分析

Next AI Draw.io 核心实现深度分析 请关注公众号【碳硅化合物AI】 前言 大家好&#xff01;上一篇我们聊了项目的整体架构&#xff0c;今天咱们深入代码&#xff0c;看看这 8 个核心模块是怎么实现的。我会从入口类开始&#xff0c;分析关键类的关系&#xff0c;然后用时序图…

作者头像 李华
网站建设 2026/6/10 12:51:33

YOLO开源项目推荐:这10个高星项目都用了我们的GPU

YOLO开源项目推荐&#xff1a;这10个高星项目都用了我们的GPU 在智能制造车间的高速生产线上&#xff0c;每分钟有上千个产品经过质检工位。传统人工检测不仅效率低、易疲劳&#xff0c;还难以应对微米级缺陷识别。如今&#xff0c;越来越多工厂选择部署基于YOLO的目标检测系统…

作者头像 李华