From 0a26a4146baee24cc41740f48b5739fe1789b1a4 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 4 Jan 2017 12:42:04 +0100 Subject: [PATCH] Make `spring.session.store-type` mandatory This commit removes the automatic enabling of Redis as the Spring Session store when it is available. This case is covered by a warning in `1.4.x` that this commit removes as well. Closes gh-7858 --- .../session/RedisSessionConfiguration.java | 17 +---------------- .../session/SessionCondition.java | 12 ++---------- .../SessionAutoConfigurationRedisTests.java | 18 +----------------- .../main/asciidoc/spring-boot-features.adoc | 5 +---- 4 files changed, 5 insertions(+), 47 deletions(-) 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 2570868139..7703e0d580 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,6 @@ package org.springframework.boot.autoconfigure.session; -import javax.annotation.PostConstruct; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -45,8 +40,6 @@ import org.springframework.session.data.redis.config.annotation.web.http.RedisHt @Conditional(SessionCondition.class) class RedisSessionConfiguration { - private static final Log logger = LogFactory.getLog(RedisSessionConfiguration.class); - @Configuration public static class SpringBootRedisHttpSessionConfiguration extends RedisHttpSessionConfiguration { @@ -65,14 +58,6 @@ class RedisSessionConfiguration { setRedisFlushMode(redis.getFlushMode()); } - @PostConstruct - public void validate() { - if (this.sessionProperties.getStoreType() == null) { - logger.warn("Spring Session store type is mandatory: set " - + "'spring.session.store-type=redis' in your configuration"); - } - } - } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionCondition.java index f86ff340de..a210a7bfac 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,19 +23,15 @@ import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.annotation.ConditionContext; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.util.ClassUtils; /** * General condition used with all session configuration classes. * * @author Tommy Ludwig + * @author Stephane Nicoll */ class SessionCondition extends SpringBootCondition { - private static final boolean redisPresent = ClassUtils.isPresent( - "org.springframework.data.redis.core.RedisTemplate", - SessionCondition.class.getClassLoader()); - @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { @@ -46,10 +42,6 @@ class SessionCondition extends SpringBootCondition { StoreType sessionStoreType = SessionStoreMappings .getType(((AnnotationMetadata) metadata).getClassName()); if (!resolver.containsProperty("store-type")) { - if (sessionStoreType == StoreType.REDIS && redisPresent) { - return ConditionOutcome.match( - message.foundExactly("default store type of redis (deprecated)")); - } return ConditionOutcome.noMatch( message.didNotFind("spring.session.store-type property").atAll()); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java index dd7b2d05e6..0c0a3ac65b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,13 +24,10 @@ import org.junit.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.boot.redis.RedisTestServer; -import org.springframework.boot.test.rule.OutputCapture; import org.springframework.session.data.redis.RedisFlushMode; import org.springframework.session.data.redis.RedisOperationsSessionRepository; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.Matchers.containsString; /** * Redis specific tests for {@link SessionAutoConfiguration}. @@ -40,27 +37,14 @@ import static org.hamcrest.Matchers.containsString; public class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfigurationTests { - @Rule - public OutputCapture output = new OutputCapture(); - @Rule public final RedisTestServer redis = new RedisTestServer(); - @Test - public void redisSessionStoreIsTheDefault() { - load(Collections.>singletonList(RedisAutoConfiguration.class)); - validateSpringSessionUsesRedis(); - this.output.expect(containsString( - "Spring Session store type is mandatory: set 'spring.session.store-type=redis' in your configuration")); - } - @Test public void redisSessionStore() { load(Collections.>singletonList(RedisAutoConfiguration.class), "spring.session.store-type=redis"); validateSpringSessionUsesRedis(); - this.output.expect(not(containsString( - "Spring Session store type is mandatory: set 'spring.session.store-type=redis' in your configuration"))); } private void validateSpringSessionUsesRedis() { diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 7ae10ce437..19907d9edf 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -4998,7 +4998,7 @@ Spring Boot provides Spring Session auto-configuration for a wide range of store * Hazelcast * HashMap -If Spring Session is available, you only need to choose the +If Spring Session is available, you must choose the {sc-spring-boot-autoconfigure}/session/StoreType.{sc-ext}[`StoreType`] that you wish to use to store the sessions. For instance to use JDBC as backend store, you'd configure your application as follows: @@ -5008,9 +5008,6 @@ your application as follows: spring.session.store-type=jdbc ---- -NOTE: For backward compatibility if Redis is available Spring Session will be automatically -configured to use Redis. - TIP: You can disable Spring Session by setting the `store-type` to `none`. Each store has specific additional settings. For instance it is possible to customize