Files
springboot-demo/src/main/java/com/example/demo/aop/RateLimited.java

28 lines
572 B
Java
Raw Normal View History

package com.example.demo.aop;
import java.lang.annotation.*;
/**
* 限流注解 - 自定义注解配合 AOP 使用
*
* 学习点
* - 自定义注解定义
* - @Retention 保留策略
* - @Target 目标元素
* - 注解 + AOP 实现声明式功能
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Documented
public @interface RateLimited {
/**
* 每分钟最大请求数
*/
long value() default 100;
/**
* 限流提示消息
*/
String message() default "请求过于频繁,请稍后再试";
}