Skip to content

xw-zzz/xw-distributed-lock-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

分布式锁starter

通过Redis实现分布式锁,封装成starter开箱即用,支持通过注解实现分布式锁,key支持通过SPEL表达式自定义。

使用

  1. 引入依赖

            <dependency>
                <groupId>io.github.xw-zzz</groupId>
                <artifactId>xw-distributed-lock-starter</artifactId>
                <version>1.0.0-RELEASE</version>
            </dependency>
  2. 在Springboot主类@EnableAspectJAutoProxy注解

    @SpringBootApplication()
    @EnableAspectJAutoProxy
    public class DistridubutedLockTestApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(DistridubutedLockTestApplication.class, args);
        }
    
    }
  3. 配置redis配置

    spring.redis.host=xxxx
    spring.redis.port=6379
    spring.redis.password=xxx
  4. 使用案例

    • 支持SPEL表达式设定key
        @GetMapping("/test/lock")
        @DistributedLock(lockKey = "111",value = "2222",throwExceptionWhenLockFailed = true)
        public void lock() throws InterruptedException {
            System.out.println("加锁成功!!!!!!!!");
            TimeUnit.SECONDS.sleep(111); 
        }
    
        @GetMapping("/test/lock1/{name}")
        @DistributedLock(lockKey = "#name",value = "2222",throwExceptionWhenLockFailed = true)
        public void lock1(@PathVariable String name) throws InterruptedException {
            System.out.println("加锁成功!!!!!!!!");
            TimeUnit.SECONDS.sleep(111); 
        }

About

基于Spring Boot的分布式锁starter,开箱即用

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages