Spring Boot application integrates rate limitation quickly, to prevent too frequent accesses.
- Import dependencies
<dependency>
<groupId>cn.unikue.springstarter</groupId>
<artifactId>resource-handler-spring-boot-starter</artifactId>
<version>LATEST</version>
</dependency>By default, this starter will auto take effect, you can turn it off by
spring.resource-handler.enabled = false
- Configure Spring Boot
application.ymlwith prefixspring.resource-handler(Optional)
spring:
resource-handler:
resource-mapping:
add-default-versional: true
add-default-original: false
versional:
- '/foo/**': 'classpath:/foo/'
original:
- '/bar/**': 'classpath:/bar/'
virtual-root:
resource: 'classpath:/vroot/'-
Optional feature: If you don't like putting many files under the
src/main/resourcesfolder directly, you'd better try thevirtual-rootfeature. This will add the virtual mapping "/vroot/**" to theoriginalmapping, thus you can put files under the foldersrc/main/resources/vroot, then you can access them by://domain/file. This is useful forfavicon.ico,robot.txt, etc. -
Annotate your (non-static) method with
@RateLimitedannotation, done!
The
keyTypeattribute of the annotation, is the limitation ways, supports
-
IP address
-
session
-
username
-
This starter needs to save the limitation data to somewhere, currently is
- redis
- jdk 17+
This project is under the Apache License 2.0
See the NOTICE.txt file for required notices and attributions.
You like this package? Then donate to us to support the development.
Beijing Unikue Network Technology Ltd.
- Unikue: https://unikue.cn