ConditionalOnRateLimitStore class final

Registers a RateLimitStore bean when it is the one the application asked for, or the best it has: how a library offers its store to the rate limiter, and how the framework's own are chosen.

It matches when the rate limiter is on, no RateLimitStore is registered yet, and

  • spring.web.rate-limit.store is name, or
  • that property is not set and byDefault matches (when given).

The stores are asked in the order of their modules, the most specific first (a module names the ones it comes after), and the first that matches is the default; a bean of the application is registered before them all and wins.

// A store over Redis, the default when the application has a client.
BeanDefinition<RateLimitStore>(
  name: 'redisRateLimitStore',
  conditions: const [
    ConditionGroup('redisRateLimitStore', [
      ConditionalOnRateLimitStore(
        'redis',
        byDefault: ConditionalOnBean(RedisClient),
      ),
    ]),
  ],
  create: (r) => RedisRateLimitStore(r.dependency<RedisClient>()),
)

Spring Boot chooses a CacheManager the same way: spring.cache.type names one, else the first of CacheConfigurations whose condition matches.

Implemented types

Constructors

ConditionalOnRateLimitStore(String name, {Condition? byDefault})
The condition of the store called name.
const

Properties

byDefault → Condition?
What must hold for this store to be the default; null: nothing.
final
configurationPhase → ConfigurationPhase
Decided when the bean definitions are registered, so that it sees the stores of the modules before.
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
name → String
The value of spring.web.rate-limit.store that asks for this store.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

matches(ConditionContext context) → bool
Whether the annotated bean should be registered; context gives access to the configuration and the definitions registered so far.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited