Spring Boot application integrates rate limitation quickly, to prevent too frequent accesses.
- Import dependencies
<dependency>
<groupId>com.yookue.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.yml
with 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/resources
folder directly, you'd better try thevirtual-root
feature. This will add the virtual mapping "/vroot/**" to theoriginal
mapping, 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
@RateLimited
annotation, done!
The
keyType
attribute 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 Yookue Network Technology Ltd.
- Yookue: https://yookue.com