Skip to content

Configuration

Garvit Joshi edited this page Nov 14, 2026 · 10 revisions

Locksmith has three properties, each with a default:

locksmith:
  enabled: true              # default true
  key-prefix: "locksmith:"   # default "locksmith:"
  semaphore:
    lease-time: 5m           # default 5m
Property Default Meaning
locksmith.enabled true true or false, in any case; false switches Locksmith off, and any other value fails the startup
locksmith.key-prefix locksmith: prefix of every Redis key; blank falls back to the default
locksmith.semaphore.lease-time 5m lease of a permit when leaseTime is blank or not set; must be at least one millisecond

There are no other properties.

Your own RedissonClient bean

redisson-spring-boot-starter, used in the installation, supplies the RedissonClient bean. If you define the client yourself instead of using the Redisson starter, depend on org.redisson:redisson and declare the bean:

@Configuration
public class RedisConfig {

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://localhost:6379");
        return Redisson.create(config);
    }
}

Startup

Startup line. When Locksmith is active it logs one INFO line, for example:

Locksmith enabled: key-prefix [locksmith:], semaphore lease-time PT5M, Spring Boot 4.1.1, Redisson 4.8.0

No RedissonClient bean. Locksmith registers itself only when a RedissonClient bean exists, whether it comes from Redisson's starter, from your own configuration or from another auto-configuration. Without one it registers nothing and logs one WARN at startup: Locksmith is inactive: there is no RedissonClient bean, so annotated methods run without any coordination.

locksmith.enabled=false. Locksmith registers nothing and logs one WARN: Locksmith is disabled: annotated methods run without any coordination. Annotated methods then run as plain methods, with no lock and no permit. A bean that injects LockOperations or SemaphoreOperations fails the startup with a missing bean; this is intended.

locksmith.enabled must be true or false. Any other value, an empty one included, fails the startup with a LocksmithConfigurationException that names it, for example locksmith.enabled must be true or false, got [treu], so a mistyped value never switches Locksmith off without a word.

A locksmith.semaphore.lease-time below one millisecond, including zero and negative values, also fails the startup.

Startup validation

Locksmith checks every @DistributedLock and @DistributedSemaphore when its bean is created: the method is not private, static or final, nor package-private in a class of another package or class loader than the bean's, which Spring's proxy never intercepts (in Kotlin, mark the class and the method open), the key is not blank and parses, every template variable exists, the durations parse and are in range, permits resolves to a positive integer, onFailure and handler agree, with exactly one handler bean, and the return type does not let the work run after the lock or permit is released (see Return types that are rejected). On a bean that is itself a JDK proxy, such as a Feign or HTTP interface client, a method's annotations must sit on one declaration: a method it inherits from two interfaces that annotate it differently fails, because only one declaration would be read. Declare the method again, with all its annotations, in the interface that extends the two. On a bean of a class that implements two interfaces which annotate the same method, each annotation is taken from the first interface in the implements list that has it, as Spring does for @Transactional; put the annotations on the method in the class to choose. An annotation on an interface method does not apply when the class inherits that method from a superclass that does not implement the interface: override the method in the bean's class and annotate it there. A misconfiguration throws LocksmithConfigurationException naming the class, the method and the value, and the application context refresh fails, so the application does not start. For example:

@DistributedLock on com.example.OrderService.process: waitTime [5x] is not a duration such as 5s or PT5S

The final-method check is strict: a final method is rejected even with interface proxies, where Spring would reach it through the interface. Drop final there too.

The package-private check assumes Spring's own proxy class loader. If you set your own on the auto-proxy creator, keep annotated methods public or protected: the check cannot see that class loader, and a package-private method would run without coordination.

Logging

Locksmith logs one DEBUG line per release and per failed acquire, under loggers in in.riido.locksmith. To see them:

logging:
  level:
    in.riido.locksmith: DEBUG

WARN lines appear only for events an operator should see: a lease that ran out, a failed release, a permit wait that Redisson never ended, a failure to record the locksmith.held timer, Locksmith disabled or inactive.

An ERROR line appears on each call of an annotated method that returns work still pending, or work whose completion cannot be checked, which may run after the lock or permit is released; see Return types that are rejected.

Clone this wiki locally