IT评测·应用市场-qidao123.com技术社区
标题:
11-SpringBoot3入门-整合aop
[打印本页]
作者:
络腮胡菲菲
时间:
2025-4-1 22:07
标题:
11-SpringBoot3入门-整合aop
1、概念(个人理解)
AOP(Aspect Oriented Programming),面向切面编程。
1)切面(Aspect):提供切入毗连点的方法
2)毗连点(Joinpoint):即被切入的方法
2、整合
1)添加依靠
<!--aop-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
复制代码
2)创建切面类(Aspect)
比如在service层的所有类的所有方法实行前打印日记信息。
package com.sgu.advice;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
/**
* 满堂花醉三千客,一剑寒霜十四州。
*
* @Author 中瑞
* @Date 2025/3/31 20:56
*/
@Component
@Aspect
public class logAdvice {
// 在service层的所有类的所有方法执行前打印日志信息
@Before("execution(* com..service.*.*(..))")
public void before(JoinPoint joinPoint){
System.out.println("LogAdvice.before");
System.out.println("joinPoint = " + joinPoint);
}
}
复制代码
控制台输出
3、参考
150-springboot-aop和tx整合和配置_哔哩哔哩_bilibili
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/)
Powered by Discuz! X3.4