diff --git a/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java b/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java index 673b46e..d20e94a 100644 --- a/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java +++ b/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java @@ -145,10 +145,18 @@ public class ReactiveMongoOperationsSessionRepository implements ReactorSessionR this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds; } + public Integer getMaxInactiveIntervalInSeconds() { + return maxInactiveIntervalInSeconds; + } + public void setCollectionName(String collectionName) { this.collectionName = collectionName; } + public String getCollectionName() { + return collectionName; + } + public MongoOperations getBlockingMongoOperations() { return this.blockingMongoOperations; } diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java index 4220dc0..24ac698 100644 --- a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java @@ -93,4 +93,19 @@ public class ReactiveMongoWebSessionConfiguration implements EmbeddedValueResolv public void setEmbeddedValueResolver(StringValueResolver embeddedValueResolver) { this.embeddedValueResolver = embeddedValueResolver; } + public Integer getMaxInactiveIntervalInSeconds() { + return maxInactiveIntervalInSeconds; + } + + public void setMaxInactiveIntervalInSeconds(Integer maxInactiveIntervalInSeconds) { + this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds; + } + + public String getCollectionName() { + return collectionName; + } + + public void setCollectionName(String collectionName) { + this.collectionName = collectionName; + } } diff --git a/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java b/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java index bb5e2cc..46e9fae 100644 --- a/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java +++ b/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java @@ -17,6 +17,8 @@ package org.springframework.session.data.mongo.config.annotation.web.reactive; import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; +import static org.mockito.BDDMockito.times; +import static org.mockito.BDDMockito.verify; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; @@ -155,6 +157,18 @@ public class ReactiveMongoWebSessionConfigurationTest { verify(indexOperations, times(1)).ensureIndex(any()); } + @Test + public void overrideCollectionAndInactiveIntervalThroughConfigurationOptions() { + + this.context = new AnnotationConfigApplicationContext(); + this.context.register(CustomizedReactiveConfiguration.class); + this.context.refresh(); + + ReactiveMongoOperationsSessionRepository repository = this.context.getBean(ReactiveMongoOperationsSessionRepository.class); + assertThat(repository.getCollectionName()).isEqualTo("custom-collection"); + assertThat(repository.getMaxInactiveIntervalInSeconds()).isEqualTo(123); + } + /** * Reflectively extract the {@link AbstractMongoSessionConverter} from the {@link ReactiveMongoOperationsSessionRepository}. * This is to avoid expanding the surface area of the API. @@ -240,4 +254,19 @@ public class ReactiveMongoWebSessionConfigurationTest { return mongoOperations; } } + + @EnableSpringWebSession + static class CustomizedReactiveConfiguration extends ReactiveMongoWebSessionConfiguration { + + @Bean + ReactiveMongoOperations reactiveMongoOperations() { + return mock(ReactiveMongoOperations.class); + } + + public CustomizedReactiveConfiguration() { + + this.setCollectionName("custom-collection"); + this.setMaxInactiveIntervalInSeconds(123); + } + } }