Skip to content

Configuration

Garvit Joshi edited this page Oct 9, 2026 · 8 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. 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, and onFailure and handler agree, with exactly one handler bean. 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 failure to record the locksmith.held timer, Locksmith disabled or inactive.

Clone this wiki locally