# distributed-lock-spring-boot-starter **Repository Path**: stark-lab/distributed-lock-spring-boot-starter ## Basic Information - **Project Name**: distributed-lock-spring-boot-starter - **Description**: 基于 redis 的分布式锁。 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-20 - **Last Updated**: 2025-10-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [![](https://img.shields.io/badge/Maven%20Central-v1.0.0-brightgreen)](https://central.sonatype.com/artifact/io.github.benfromchina/distributed-lock-spring-boot-starter/1.0.0) [![](https://img.shields.io/badge/Release-v1.0.0-blue)](https://gitee.com/stark-lab/distributed-lock-spring-boot-starter/releases/v1.0.0) [![](https://img.shields.io/badge/License-Apache--2.0-9cf)](https://www.apache.org/licenses/LICENSE-2.0.html) [![](https://img.shields.io/badge/JDK-17+-9cf)]() # 分布式锁 Spring Boot Starter 这是一个为 Spring Boot 项目提供分布式锁功能的启动器,支持通过 Redis 实现分布式锁。 ## 特性 - 基于注解的分布式锁管理。 - 支持 Redis 作为分布式锁的实现。 - 可配置的锁超时时间。 - 简洁的 AOP 实现,对业务代码无侵入。 ## 使用方法 ### 1. 添加依赖 在 `pom.xml` 中添加以下依赖: ```xml io.github.benfromchina distributed-lock-spring-boot-starter 1.0.0 ``` ### 2. 配置 Redis 在 `application.yml` 或 `application.properties` 中配置 Redis 连接信息及分布式锁相关参数: ```yaml spring: lock: redis: cacheName: myLocks timeout: 3000 ``` ### 3. 使用 `@DistributedLock` 注解 在需要加锁的方法上添加 `@DistributedLock` 注解: ```java @Service public class MyService { @DistributedLock public void doSomething() { // 业务逻辑 } } ``` ## 模块说明 - **`@DistributedLock` 注解**:用于标记需要加锁的方法。 - **`DistributedLockAspect`**:AOP 实现,负责处理加锁和释放锁的逻辑。 - **`MethodExpressionEvaluator`**:用于解析方法中的表达式,动态获取锁的键值。 - **`DistributedLockProperties`**:配置类,用于读取锁的配置参数。 - **`RedisLockRegistry`**:Redis 实现的分布式锁注册中心。 ## 异常处理 如果在获取锁的过程中出现异常,会抛出 `DistributedLockException`,请根据业务需求进行处理。 ## 贡献指南 欢迎提交 PR 或 issue,为本项目提供更好的功能和文档支持。请遵循项目的编码规范,并确保所有更改都有相应的测试覆盖。 ## 许可证 本项目基于 Apache-2.0 许可证发布,请参阅 [LICENSE](LICENSE) 文件了解更多详情。