Spring Boot通过切面实现方法耗时情况

Spring Boot通过切面实现方法耗时情况

依赖

xml 复制代码
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.9.9.1</version>
        </dependency>

自定义注解

java 复制代码
package com.geekmice.springbootselfexercise.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @author PMB
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MethodExporter {
}

切面类

java 复制代码
package com.geekmice.springbootselfexercise.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: spring-boot-scaffold
 * @BelongsPackage: com.geekmice.com.geekmice.sbpagehelper.utils
 * @Author: pingmingbo
 * @CreateTime: 2023-07-26  21:52
 * @Description: TODO
 * @Version: 1.0
 */
@Aspect
@Component
@Slf4j
public class MethodExporterAspect {
    @Around("@annotation(com.geekmice.springbootselfexercise.annotation.MethodExporter)")
    public Object methodExporter(ProceedingJoinPoint point) throws Throwable {
        long start = System.currentTimeMillis() / 1000;
        Object proceed = point.proceed();
        long end = System.currentTimeMillis() / 1000;
        log.info("【耗时:】{}s", (end - start));
        return proceed;
    }
}

控制层

java 复制代码
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    @PostMapping(value = "uploadFileByEasyPoi")
    @MethodExporter
    @ApiOperation(value = "通过easypoi上传文件")
    public AjaxResult uploadFileByEasyPoi(@RequestPart MultipartFile file){
        userService.uploadFileByEasyPoi(file);
        return AjaxResult.success();
    }
相关推荐
千寻技术帮1 小时前
10361_基于Springboot的哈尔滨旅游管理系统
数据库·spring boot·mysql·毕业设计·旅游
步菲2 小时前
springboot canche 无法避免Null key错误, Null key returned for cache operation
java·开发语言·spring boot
毕设源码-朱学姐2 小时前
【开题答辩全过程】以 基于SpringBoot的中医理疗就诊系统为例,包含答辩的问题和答案
java·spring boot·后端
2201_757830876 小时前
全局异常处理器
java
上进小菜猪6 小时前
从人工目检到 AI 质检-YOLOv8 驱动的 PCB 缺陷检测系统【完整源码】
后端
小徐Chao努力7 小时前
【Langchain4j-Java AI开发】09-Agent智能体工作流
java·开发语言·人工智能
Coder_Boy_7 小时前
SpringAI与LangChain4j的智能应用-(理论篇2)
人工智能·spring boot·langchain·springai
Coder_Boy_7 小时前
SpringAI与LangChain4j的智能应用-(理论篇3)
java·人工智能·spring boot·langchain
Coder_Boy_7 小时前
基于SpringAI的智能平台基座开发-(六)
java·数据库·人工智能·spring·langchain·langchain4j
阿狸远翔8 小时前
Protobuf 和 protoc-gen-go 详解
开发语言·后端·golang