Merge pull request #18470 from vpavic

* gh-18470:
  Align with Spring Session MongoDB deprecations

Closes gh-18470
pull/18477/head
Andy Wilkinson 5 years ago
commit 5a6e6cc53d

@ -27,7 +27,7 @@ import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.ReactiveMongoOperations; import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.session.ReactiveSessionRepository; import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.data.mongo.ReactiveMongoOperationsSessionRepository; import org.springframework.session.data.mongo.ReactiveMongoSessionRepository;
import org.springframework.session.data.mongo.config.annotation.web.reactive.ReactiveMongoWebSessionConfiguration; import org.springframework.session.data.mongo.config.annotation.web.reactive.ReactiveMongoWebSessionConfiguration;
/** /**
@ -36,7 +36,7 @@ import org.springframework.session.data.mongo.config.annotation.web.reactive.Rea
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ ReactiveMongoOperations.class, ReactiveMongoOperationsSessionRepository.class }) @ConditionalOnClass({ ReactiveMongoOperations.class, ReactiveMongoSessionRepository.class })
@ConditionalOnMissingBean(ReactiveSessionRepository.class) @ConditionalOnMissingBean(ReactiveSessionRepository.class)
@ConditionalOnBean(ReactiveMongoOperations.class) @ConditionalOnBean(ReactiveMongoOperations.class)
@Conditional(ReactiveSessionCondition.class) @Conditional(ReactiveSessionCondition.class)

@ -27,7 +27,7 @@ import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.session.SessionRepository; import org.springframework.session.SessionRepository;
import org.springframework.session.data.mongo.MongoOperationsSessionRepository; import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
import org.springframework.session.data.mongo.config.annotation.web.http.MongoHttpSessionConfiguration; import org.springframework.session.data.mongo.config.annotation.web.http.MongoHttpSessionConfiguration;
/** /**
@ -37,7 +37,7 @@ import org.springframework.session.data.mongo.config.annotation.web.http.MongoHt
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ MongoOperations.class, MongoOperationsSessionRepository.class }) @ConditionalOnClass({ MongoOperations.class, MongoIndexedSessionRepository.class })
@ConditionalOnMissingBean(SessionRepository.class) @ConditionalOnMissingBean(SessionRepository.class)
@ConditionalOnBean(MongoOperations.class) @ConditionalOnBean(MongoOperations.class)
@Conditional(ServletSessionCondition.class) @Conditional(ServletSessionCondition.class)

@ -266,7 +266,7 @@ public class SessionAutoConfiguration {
super(applicationContext, sessionProperties, super(applicationContext, sessionProperties,
Arrays.asList("org.springframework.session.hazelcast.HazelcastIndexedSessionRepository", Arrays.asList("org.springframework.session.hazelcast.HazelcastIndexedSessionRepository",
"org.springframework.session.jdbc.JdbcIndexedSessionRepository", "org.springframework.session.jdbc.JdbcIndexedSessionRepository",
"org.springframework.session.data.mongo.MongoOperationsSessionRepository", "org.springframework.session.data.mongo.MongoIndexedSessionRepository",
"org.springframework.session.data.redis.RedisIndexedSessionRepository")); "org.springframework.session.data.redis.RedisIndexedSessionRepository"));
} }
@ -283,7 +283,7 @@ public class SessionAutoConfiguration {
SessionProperties sessionProperties) { SessionProperties sessionProperties) {
super(applicationContext, sessionProperties, super(applicationContext, sessionProperties,
Arrays.asList("org.springframework.session.data.redis.ReactiveRedisSessionRepository", Arrays.asList("org.springframework.session.data.redis.ReactiveRedisSessionRepository",
"org.springframework.session.data.mongo.ReactiveMongoOperationsSessionRepository")); "org.springframework.session.data.mongo.ReactiveMongoSessionRepository"));
} }
} }

@ -28,7 +28,7 @@ import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext; import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
import org.springframework.session.data.mongo.ReactiveMongoOperationsSessionRepository; import org.springframework.session.data.mongo.ReactiveMongoSessionRepository;
import org.springframework.session.data.redis.ReactiveRedisSessionRepository; import org.springframework.session.data.redis.ReactiveRedisSessionRepository;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -74,8 +74,8 @@ class ReactiveSessionAutoConfigurationMongoTests extends AbstractSessionAutoConf
private ContextConsumer<AssertableReactiveWebApplicationContext> validateSpringSessionUsesMongo( private ContextConsumer<AssertableReactiveWebApplicationContext> validateSpringSessionUsesMongo(
String collectionName) { String collectionName) {
return (context) -> { return (context) -> {
ReactiveMongoOperationsSessionRepository repository = validateSessionRepository(context, ReactiveMongoSessionRepository repository = validateSessionRepository(context,
ReactiveMongoOperationsSessionRepository.class); ReactiveMongoSessionRepository.class);
assertThat(repository.getCollectionName()).isEqualTo(collectionName); assertThat(repository.getCollectionName()).isEqualTo(collectionName);
}; };
} }

@ -26,7 +26,7 @@ import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplic
import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
import org.springframework.session.SaveMode; import org.springframework.session.SaveMode;
import org.springframework.session.data.mongo.ReactiveMongoOperationsSessionRepository; import org.springframework.session.data.mongo.ReactiveMongoSessionRepository;
import org.springframework.session.data.redis.ReactiveRedisSessionRepository; import org.springframework.session.data.redis.ReactiveRedisSessionRepository;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -53,7 +53,7 @@ class ReactiveSessionAutoConfigurationRedisTests extends AbstractSessionAutoConf
@Test @Test
void defaultConfigWithUniqueStoreImplementation() { void defaultConfigWithUniqueStoreImplementation() {
this.contextRunner.withClassLoader(new FilteredClassLoader(ReactiveMongoOperationsSessionRepository.class)) this.contextRunner.withClassLoader(new FilteredClassLoader(ReactiveMongoSessionRepository.class))
.withConfiguration( .withConfiguration(
AutoConfigurations.of(RedisAutoConfiguration.class, RedisReactiveAutoConfiguration.class)) AutoConfigurations.of(RedisAutoConfiguration.class, RedisReactiveAutoConfiguration.class))
.run(validateSpringSessionUsesRedis("spring:session:", SaveMode.ON_SET_ATTRIBUTE)); .run(validateSpringSessionUsesRedis("spring:session:", SaveMode.ON_SET_ATTRIBUTE));

@ -28,7 +28,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.session.FlushMode; import org.springframework.session.FlushMode;
import org.springframework.session.SaveMode; import org.springframework.session.SaveMode;
import org.springframework.session.data.mongo.MongoOperationsSessionRepository; import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
import org.springframework.session.data.redis.RedisIndexedSessionRepository; import org.springframework.session.data.redis.RedisIndexedSessionRepository;
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
import org.springframework.session.jdbc.JdbcIndexedSessionRepository; import org.springframework.session.jdbc.JdbcIndexedSessionRepository;
@ -59,7 +59,7 @@ class SessionAutoConfigurationHazelcastTests extends AbstractSessionAutoConfigur
void defaultConfigWithUniqueStoreImplementation() { void defaultConfigWithUniqueStoreImplementation() {
this.contextRunner this.contextRunner
.withClassLoader(new FilteredClassLoader(JdbcIndexedSessionRepository.class, .withClassLoader(new FilteredClassLoader(JdbcIndexedSessionRepository.class,
RedisIndexedSessionRepository.class, MongoOperationsSessionRepository.class)) RedisIndexedSessionRepository.class, MongoIndexedSessionRepository.class))
.run(this::validateDefaultConfig); .run(this::validateDefaultConfig);
} }

@ -32,7 +32,7 @@ import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.session.FlushMode; import org.springframework.session.FlushMode;
import org.springframework.session.SaveMode; import org.springframework.session.SaveMode;
import org.springframework.session.data.mongo.MongoOperationsSessionRepository; import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
import org.springframework.session.data.redis.RedisIndexedSessionRepository; import org.springframework.session.data.redis.RedisIndexedSessionRepository;
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
import org.springframework.session.jdbc.JdbcIndexedSessionRepository; import org.springframework.session.jdbc.JdbcIndexedSessionRepository;
@ -63,7 +63,7 @@ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfiguration
void defaultConfigWithUniqueStoreImplementation() { void defaultConfigWithUniqueStoreImplementation() {
this.contextRunner this.contextRunner
.withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class, .withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class,
MongoOperationsSessionRepository.class, RedisIndexedSessionRepository.class)) MongoIndexedSessionRepository.class, RedisIndexedSessionRepository.class))
.run(this::validateDefaultConfig); .run(this::validateDefaultConfig);
} }

@ -26,7 +26,7 @@ import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.session.data.mongo.MongoOperationsSessionRepository; import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
import org.springframework.session.data.redis.RedisIndexedSessionRepository; import org.springframework.session.data.redis.RedisIndexedSessionRepository;
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
import org.springframework.session.jdbc.JdbcIndexedSessionRepository; import org.springframework.session.jdbc.JdbcIndexedSessionRepository;
@ -72,8 +72,8 @@ class SessionAutoConfigurationMongoTests extends AbstractSessionAutoConfiguratio
private ContextConsumer<AssertableWebApplicationContext> validateSpringSessionUsesMongo(String collectionName) { private ContextConsumer<AssertableWebApplicationContext> validateSpringSessionUsesMongo(String collectionName) {
return (context) -> { return (context) -> {
MongoOperationsSessionRepository repository = validateSessionRepository(context, MongoIndexedSessionRepository repository = validateSessionRepository(context,
MongoOperationsSessionRepository.class); MongoIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("collectionName", collectionName); assertThat(repository).hasFieldOrPropertyWithValue("collectionName", collectionName);
}; };
} }

@ -35,7 +35,7 @@ import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.session.FlushMode; import org.springframework.session.FlushMode;
import org.springframework.session.SaveMode; import org.springframework.session.SaveMode;
import org.springframework.session.data.mongo.MongoOperationsSessionRepository; import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
import org.springframework.session.data.redis.RedisIndexedSessionRepository; import org.springframework.session.data.redis.RedisIndexedSessionRepository;
import org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction; import org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction;
import org.springframework.session.data.redis.config.ConfigureRedisAction; import org.springframework.session.data.redis.config.ConfigureRedisAction;
@ -75,7 +75,7 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
void defaultConfigWithUniqueStoreImplementation() { void defaultConfigWithUniqueStoreImplementation() {
this.contextRunner this.contextRunner
.withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class, .withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class,
JdbcIndexedSessionRepository.class, MongoOperationsSessionRepository.class)) JdbcIndexedSessionRepository.class, MongoIndexedSessionRepository.class))
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
.withPropertyValues("spring.redis.port=" + redis.getFirstMappedPort()) .withPropertyValues("spring.redis.port=" + redis.getFirstMappedPort())
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE, .run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE,

Loading…
Cancel
Save