diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HashMapSessionConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HashMapSessionConfiguration.java index 332df6d272..1909ed45f7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HashMapSessionConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HashMapSessionConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.session; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; @@ -33,6 +34,7 @@ import org.springframework.session.config.annotation.web.http.EnableSpringHttpSe @Configuration @EnableSpringHttpSession @Conditional(SessionCondition.class) +@ConditionalOnMissingBean(SessionRepository.class) class HashMapSessionConfiguration { @Bean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HazelcastSessionConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HazelcastSessionConfiguration.java index 6667e2b923..d157a7f1c3 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HazelcastSessionConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HazelcastSessionConfiguration.java @@ -20,8 +20,10 @@ import com.hazelcast.core.HazelcastInstance; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; +import org.springframework.session.SessionRepository; import org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration; /** @@ -32,6 +34,7 @@ import org.springframework.session.hazelcast.config.annotation.web.http.Hazelcas * @author Stephane Nicoll */ @Configuration +@ConditionalOnMissingBean(SessionRepository.class) @ConditionalOnBean(HazelcastInstance.class) @Conditional(SessionCondition.class) class HazelcastSessionConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionConfiguration.java index ce82048e2c..b4fae61db4 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionConfiguration.java @@ -20,8 +20,10 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; +import org.springframework.session.SessionRepository; import org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration; /** @@ -31,6 +33,7 @@ import org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessi * @author Stephane Nicoll */ @Configuration +@ConditionalOnMissingBean(SessionRepository.class) @ConditionalOnBean(DataSource.class) @Conditional(SessionCondition.class) class JdbcSessionConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/MongoSessionConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/MongoSessionConfiguration.java index 2c8ac38703..bab9710e45 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/MongoSessionConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/MongoSessionConfiguration.java @@ -18,9 +18,11 @@ package org.springframework.boot.autoconfigure.session; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.session.SessionRepository; import org.springframework.session.data.mongo.config.annotation.web.http.MongoHttpSessionConfiguration; /** @@ -30,6 +32,7 @@ import org.springframework.session.data.mongo.config.annotation.web.http.MongoHt * @author Stephane Nicoll */ @Configuration +@ConditionalOnMissingBean(SessionRepository.class) @ConditionalOnBean(MongoOperations.class) @Conditional(SessionCondition.class) class MongoSessionConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/RedisSessionConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/RedisSessionConfiguration.java index 34413198b5..d1f59f902a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/RedisSessionConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/RedisSessionConfiguration.java @@ -18,10 +18,12 @@ package org.springframework.boot.autoconfigure.session; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.session.SessionRepository; import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration; /** @@ -33,6 +35,7 @@ import org.springframework.session.data.redis.config.annotation.web.http.RedisHt * @author Stephane Nicoll */ @Configuration +@ConditionalOnMissingBean(SessionRepository.class) @ConditionalOnBean({ RedisTemplate.class, RedisConnectionFactory.class }) @Conditional(SessionCondition.class) class RedisSessionConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java index 27f45adcd3..d4f6608a83 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java @@ -44,9 +44,9 @@ import org.springframework.session.SessionRepository; * @since 1.4.0 */ @Configuration +@ConditionalOnMissingBean(SessionRepository.class) @ConditionalOnClass(Session.class) @ConditionalOnWebApplication -@ConditionalOnMissingBean(SessionRepository.class) @EnableConfigurationProperties(SessionProperties.class) @AutoConfigureAfter({ DataSourceAutoConfiguration.class, HazelcastAutoConfiguration.class, MongoAutoConfiguration.class, RedisAutoConfiguration.class }) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/StoreType.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/StoreType.java index 0be5627260..d2bff4c416 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/StoreType.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/StoreType.java @@ -26,24 +26,24 @@ package org.springframework.boot.autoconfigure.session; public enum StoreType { /** - * JDBC backed sessions. + * Redis backed sessions. */ - JDBC, + REDIS, /** - * Mongo backed sessions. + * Hazelcast backed sessions. */ - MONGO, + HAZELCAST, /** - * Redis backed sessions. + * Mongo backed sessions. */ - REDIS, + MONGO, /** - * Hazelcast backed sessions. + * JDBC backed sessions. */ - HAZELCAST, + JDBC, /** * Simple in-memory map of sessions. diff --git a/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java b/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java index d83a112052..a18af63950 100644 --- a/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java @@ -56,6 +56,7 @@ public class SampleSessionRedisApplicationTests { if (!redisServerRunning(ex)) { return; } + throw ex; } URI uri = URI.create("http://localhost:" + port + "/");