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();
    }
相关推荐
星辰离彬16 分钟前
Java 与 MySQL 性能优化:MySQL连接池参数优化与性能提升
java·服务器·数据库·后端·mysql·性能优化
半桔17 分钟前
【Linux手册】从接口到管理:Linux文件系统的核心操作指南
android·java·linux·开发语言·面试·系统架构
nightunderblackcat25 分钟前
新手向:实现ATM模拟系统
java·开发语言·spring boot·spring cloud·tomcat·maven·intellij-idea
超级小忍29 分钟前
Spring Boot 与 Docker 的完美结合:容器化你的应用
spring boot·后端·docker
Bug退退退12331 分钟前
RabbitMQ 高级特性之延迟队列
java·spring·rabbitmq·java-rabbitmq
先睡34 分钟前
RabbitMQ
java
笑衬人心。35 分钟前
Java 17 新特性笔记
java·开发语言·笔记
麦兜*2 小时前
Spring Boot 企业级动态权限全栈深度解决方案,设计思路,代码分析
java·spring boot·后端·spring·spring cloud·性能优化·springcloud
ruan1145143 小时前
MySQL4种隔离级别
java·开发语言·mysql