Commit de4e3508 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '1.5.x'

parents e9021b36 0a26a414
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,11 +16,6 @@ ...@@ -16,11 +16,6 @@
package org.springframework.boot.autoconfigure.session; 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.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
...@@ -45,8 +40,6 @@ import org.springframework.session.data.redis.config.annotation.web.http.RedisHt ...@@ -45,8 +40,6 @@ import org.springframework.session.data.redis.config.annotation.web.http.RedisHt
@Conditional(SessionCondition.class) @Conditional(SessionCondition.class)
class RedisSessionConfiguration { class RedisSessionConfiguration {
private static final Log logger = LogFactory.getLog(RedisSessionConfiguration.class);
@Configuration @Configuration
public static class SpringBootRedisHttpSessionConfiguration public static class SpringBootRedisHttpSessionConfiguration
extends RedisHttpSessionConfiguration { extends RedisHttpSessionConfiguration {
...@@ -65,14 +58,6 @@ class RedisSessionConfiguration { ...@@ -65,14 +58,6 @@ class RedisSessionConfiguration {
setRedisFlushMode(redis.getFlushMode()); 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");
}
}
} }
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,19 +23,15 @@ import org.springframework.boot.bind.RelaxedPropertyResolver; ...@@ -23,19 +23,15 @@ import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.ClassUtils;
/** /**
* General condition used with all session configuration classes. * General condition used with all session configuration classes.
* *
* @author Tommy Ludwig * @author Tommy Ludwig
* @author Stephane Nicoll
*/ */
class SessionCondition extends SpringBootCondition { class SessionCondition extends SpringBootCondition {
private static final boolean redisPresent = ClassUtils.isPresent(
"org.springframework.data.redis.core.RedisTemplate",
SessionCondition.class.getClassLoader());
@Override @Override
public ConditionOutcome getMatchOutcome(ConditionContext context, public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) { AnnotatedTypeMetadata metadata) {
...@@ -46,10 +42,6 @@ class SessionCondition extends SpringBootCondition { ...@@ -46,10 +42,6 @@ class SessionCondition extends SpringBootCondition {
StoreType sessionStoreType = SessionStoreMappings StoreType sessionStoreType = SessionStoreMappings
.getType(((AnnotationMetadata) metadata).getClassName()); .getType(((AnnotationMetadata) metadata).getClassName());
if (!resolver.containsProperty("store-type")) { if (!resolver.containsProperty("store-type")) {
if (sessionStoreType == StoreType.REDIS && redisPresent) {
return ConditionOutcome.match(
message.foundExactly("default store type of redis (deprecated)"));
}
return ConditionOutcome.noMatch( return ConditionOutcome.noMatch(
message.didNotFind("spring.session.store-type property").atAll()); message.didNotFind("spring.session.store-type property").atAll());
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -24,13 +24,10 @@ import org.junit.Test; ...@@ -24,13 +24,10 @@ import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.redis.RedisTestServer; 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.RedisFlushMode;
import org.springframework.session.data.redis.RedisOperationsSessionRepository; import org.springframework.session.data.redis.RedisOperationsSessionRepository;
import static org.assertj.core.api.Assertions.assertThat; 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}. * Redis specific tests for {@link SessionAutoConfiguration}.
...@@ -40,27 +37,14 @@ import static org.hamcrest.Matchers.containsString; ...@@ -40,27 +37,14 @@ import static org.hamcrest.Matchers.containsString;
public class SessionAutoConfigurationRedisTests public class SessionAutoConfigurationRedisTests
extends AbstractSessionAutoConfigurationTests { extends AbstractSessionAutoConfigurationTests {
@Rule
public OutputCapture output = new OutputCapture();
@Rule @Rule
public final RedisTestServer redis = new RedisTestServer(); public final RedisTestServer redis = new RedisTestServer();
@Test
public void redisSessionStoreIsTheDefault() {
load(Collections.<Class<?>>singletonList(RedisAutoConfiguration.class));
validateSpringSessionUsesRedis();
this.output.expect(containsString(
"Spring Session store type is mandatory: set 'spring.session.store-type=redis' in your configuration"));
}
@Test @Test
public void redisSessionStore() { public void redisSessionStore() {
load(Collections.<Class<?>>singletonList(RedisAutoConfiguration.class), load(Collections.<Class<?>>singletonList(RedisAutoConfiguration.class),
"spring.session.store-type=redis"); "spring.session.store-type=redis");
validateSpringSessionUsesRedis(); validateSpringSessionUsesRedis();
this.output.expect(not(containsString(
"Spring Session store type is mandatory: set 'spring.session.store-type=redis' in your configuration")));
} }
private void validateSpringSessionUsesRedis() { private void validateSpringSessionUsesRedis() {
......
...@@ -4959,7 +4959,7 @@ Spring Boot provides Spring Session auto-configuration for a wide range of store ...@@ -4959,7 +4959,7 @@ Spring Boot provides Spring Session auto-configuration for a wide range of store
* Hazelcast * Hazelcast
* HashMap * 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 {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 use to store the sessions. For instance to use JDBC as backend store, you'd configure
your application as follows: your application as follows:
...@@ -4969,9 +4969,6 @@ your application as follows: ...@@ -4969,9 +4969,6 @@ your application as follows:
spring.session.store-type=jdbc 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`. 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 Each store has specific additional settings. For instance it is possible to customize
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment