Skip to content

Commit b467462

Browse files
refactor: migrate Bucket4j to lambda-based builder API
Replace deprecated Bandwidth.classic() with new builder pattern: - Remove Bandwidth and Refill imports (no longer needed) - Use lambda-based .addLimit() with fluent API - Change: Bandwidth.classic(capacity, Refill.greedy(...)) - To: .addLimit(limit -> limit.capacity(...).refillGreedy(...)) This eliminates the last compilation warning and aligns with Bucket4j 8.10.1+ recommended API (deprecated since 8.5.0). All 550 tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f0bcc6a commit b467462

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/main/java/com/jhf/coupon/security/RateLimitingFilter.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.jhf.coupon.security;
22

33
import com.jhf.coupon.config.RateLimitProperties;
4-
import io.github.bucket4j.Bandwidth;
54
import io.github.bucket4j.Bucket;
6-
import io.github.bucket4j.Refill;
75
import jakarta.servlet.FilterChain;
86
import jakarta.servlet.ServletException;
97
import jakarta.servlet.http.HttpServletRequest;
@@ -128,12 +126,11 @@ private Bucket resolveBucket(String clientIp, Map<String, Bucket> bucketMap, int
128126
* @return New Bucket instance
129127
*/
130128
private Bucket createNewBucket(int requestsPerMinute) {
131-
Bandwidth limit = Bandwidth.classic(
132-
requestsPerMinute,
133-
Refill.greedy(requestsPerMinute, Duration.ofMinutes(1))
134-
);
135129
return Bucket.builder()
136-
.addLimit(limit)
130+
.addLimit(limit -> limit
131+
.capacity(requestsPerMinute)
132+
.refillGreedy(requestsPerMinute, Duration.ofMinutes(1))
133+
)
137134
.build();
138135
}
139136

0 commit comments

Comments
 (0)