news 2026/2/25 12:04:10

(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/2/25 10:31:01

为什么越来越多企业用YOLO替代Faster R-CNN?

为什么越来越多企业用YOLO替代Faster R-CNN&#xff1f; 在智能制造、无人巡检和智慧交通等工业场景中&#xff0c;目标检测早已不再是实验室里的算法比拼&#xff0c;而是决定产线能否自动停机报警、摄像头能否实时识别违规行为的关键能力。十年前&#xff0c;提到高精度检测&…

作者头像 李华
网站建设 2026/2/23 10:18:41

YOLO目标检测支持Modbus TCP工业控制协议

YOLO目标检测与Modbus TCP的工业融合实践 在现代工厂的自动化产线上&#xff0c;一个看似简单的动作——剔除不合格产品——背后往往涉及复杂的系统协作。摄像头捕捉图像&#xff0c;AI判断缺陷&#xff0c;PLC控制气缸执行剔除。但现实中&#xff0c;这套流程常因“语言不通”…

作者头像 李华
网站建设 2026/2/22 21:48:45

锐捷RCNP+RCIE融合 | 虚拟专用网络概述与技术详解(1/4)

一、虚拟专用网络的基本概念 1. 虚拟专用网络的定义 在传统的企业网络配置中,分支机构要远程访问总部,通常的做法是租用专线,但是这样的通讯方案会导致高昂的网络通讯和维护费用。对于移动办公人员来说,一般会通过拨号方式通过Internet进入企业的局域网,而这样也会带来安…

作者头像 李华
网站建设 2026/2/24 5:23:56

YOLOv10来了!新架构带来的算力需求变化分析

YOLOv10来了&#xff01;新架构带来的算力需求变化分析 在工业质检流水线上&#xff0c;一个微小的划痕可能意味着整批产品的报废。而让AI系统在毫秒级时间内准确识别缺陷&#xff0c;并触发分拣动作——这不仅是算法精度的问题&#xff0c;更是一场关于确定性延迟与能效比的硬…

作者头像 李华
网站建设 2026/2/25 7:32:17

从Ping到RCE:服务器端请求伪造(SSRF)实战深度解析

为什么撰写本文 我花费数年时间研究SSRF漏洞——从阅读每一份已披露的报告&#xff0c;到在实验环境中进行测试&#xff0c;再到在授权的漏洞赏金计划中进行实践。本文汇集了我关于如何将一个简单的“服务器发起请求”转变为关键严重性发现的所有心得。 SSRF常被轻视为“仅仅是…

作者头像 李华
网站建设 2026/2/24 5:22:39

12/28-正式1级打卡题1(课后)

【AICE打卡题】围栅栏#include <iostream> using namespace std;int main() {int a, b;cin >> a >> b;if (b > 4 * a) {cout << "yes" << endl;} else {cout << "no" << endl;}return 0; }【AICE打卡题】偶数…

作者头像 李华