Skip to content

Add support for auto-configuring an indexed reactive session repository #42604

@TMRGZ

Description

@TMRGZ

As noted in the Spring Session configuration documentation, reactive indexed repositories can only be enabled through annotations, which limits the configuration flexibility via application.properties.

Additionally, the auto-configuration classes do not account for important properties such as configureRedisAction and namespace.

Simply adding the equivalent methods resolves this issue, as shown in the following configuration:

@Configuration(proxyBeanMethods = false) @ConditionalOnProperty(prefix = "spring.session.redis", name = "repository-type", havingValue = "indexed") @Import(RedisIndexedWebSessionConfiguration.class) @EnableConfigurationProperties(RedisSessionProperties.class) static class IndexedRedisSessionConfiguration { @Bean @ConditionalOnMissingBean ConfigureReactiveRedisAction configureRedisAction(RedisSessionProperties redisSessionProperties) { return switch (redisSessionProperties.getConfigureAction()) { case NOTIFY_KEYSPACE_EVENTS -> new ConfigureNotifyKeyspaceEventsReactiveAction(); case NONE -> ConfigureReactiveRedisAction.NO_OP; }; } @Bean @Order(Ordered.HIGHEST_PRECEDENCE) ReactiveSessionRepositoryCustomizer<ReactiveRedisIndexedSessionRepository> springBootSessionRepositoryCustomizer( SessionProperties sessionProperties, RedisSessionProperties redisSessionProperties, ServerProperties serverProperties) { return (sessionRepository) -> { PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); map.from(sessionProperties.determineTimeout(() -> serverProperties.getReactive().getSession().getTimeout())) .to(sessionRepository::setDefaultMaxInactiveInterval); map.from(redisSessionProperties::getNamespace).to(sessionRepository::setRedisKeyNamespace); map.from(redisSessionProperties::getSaveMode).to(sessionRepository::setSaveMode); }; } }

Additionally, it would be helpful to add a similar check for non-indexed repositories when the cleanup-cron property is enabled.

I can provide a PR if needed

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions