Merge branch 'gh-4895'

pull/4883/merge
Andy Wilkinson 9 years ago
commit 6dadac1d4f

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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.
@ -21,6 +21,7 @@ import java.net.URL;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -42,7 +43,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.ExpiringSession;
import org.springframework.util.StringUtils;
/**
@ -50,6 +50,7 @@ import org.springframework.util.StringUtils;
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Vladimir Tsanev
* @since 1.3.0
*/
@Configuration
@ -164,12 +165,14 @@ public class LocalDevToolsAutoConfiguration {
}
@Configuration
@ConditionalOnBean(name = "sessionRedisTemplate")
@ConditionalOnBean(name = RedisRestartConfiguration.SESSION_REDIS_TEMPLATE_BEAN_NAME)
static class RedisRestartConfiguration {
static final String SESSION_REDIS_TEMPLATE_BEAN_NAME = "sessionRedisTemplate";
@Bean
public RestartCompatibleRedisSerializerConfigurer restartCompatibleRedisSerializerConfigurer(
RedisTemplate<String, ExpiringSession> sessionRedisTemplate) {
@Qualifier(SESSION_REDIS_TEMPLATE_BEAN_NAME) RedisTemplate<?, ?> sessionRedisTemplate) {
return new RestartCompatibleRedisSerializerConfigurer(
sessionRedisTemplate);
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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.
@ -26,7 +26,6 @@ import org.springframework.core.serializer.support.SerializingConverter;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.session.ExpiringSession;
import org.springframework.util.ObjectUtils;
/**
@ -42,12 +41,11 @@ import org.springframework.util.ObjectUtils;
*/
class RestartCompatibleRedisSerializerConfigurer implements BeanClassLoaderAware {
private final RedisTemplate<String, ExpiringSession> redisTemplate;
private final RedisTemplate<?, ?> redisTemplate;
private volatile ClassLoader classLoader;
RestartCompatibleRedisSerializerConfigurer(
RedisTemplate<String, ExpiringSession> redisTemplate) {
RestartCompatibleRedisSerializerConfigurer(RedisTemplate<?, ?> redisTemplate) {
this.redisTemplate = redisTemplate;
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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.
@ -68,6 +68,7 @@ import static org.mockito.Mockito.verify;
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Vladimir Tsanev
*/
public class LocalDevToolsAutoConfigurationTests {
@ -241,13 +242,27 @@ public class LocalDevToolsAutoConfigurationTests {
}
@Test
public void sessionRedisTemplateIsConfiguredWithCustomDeserializers()
public void sessionRedisTemplateIsConfiguredWithCustomDeserializers10()
throws Exception {
SpringApplication application = new SpringApplication(
SessionRedisTemplateConfig.class, LocalDevToolsAutoConfiguration.class);
sessionRedisTemplateIsConfiguredWithCustomDeserializers(
Session10RedisTemplateConfig.class);
}
@Test
public void sessionRedisTemplateIsConfiguredWithCustomDeserializers11()
throws Exception {
sessionRedisTemplateIsConfiguredWithCustomDeserializers(
Session11RedisTemplateConfig.class);
}
private void sessionRedisTemplateIsConfiguredWithCustomDeserializers(
Object sessionConfig) throws Exception {
SpringApplication application = new SpringApplication(sessionConfig,
LocalDevToolsAutoConfiguration.class);
application.setWebEnvironment(false);
this.context = application.run();
RedisTemplate<?, ?> redisTemplate = this.context.getBean(RedisTemplate.class);
RedisTemplate<?, ?> redisTemplate = this.context.getBean("sessionRedisTemplate",
RedisTemplate.class);
assertThat(redisTemplate.getHashKeySerializer(),
is(instanceOf(RestartCompatibleRedisSerializer.class)));
assertThat(redisTemplate.getHashValueSerializer(),
@ -306,7 +321,7 @@ public class LocalDevToolsAutoConfigurationTests {
}
@Configuration
public static class SessionRedisTemplateConfig {
public static class Session10RedisTemplateConfig {
@Bean
public RedisTemplate<String, ExpiringSession> sessionRedisTemplate() {
@ -317,4 +332,16 @@ public class LocalDevToolsAutoConfigurationTests {
}
@Configuration
public static class Session11RedisTemplateConfig {
@Bean
public RedisTemplate<Object, Object> sessionRedisTemplate() {
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<Object, Object>();
redisTemplate.setConnectionFactory(mock(RedisConnectionFactory.class));
return redisTemplate;
}
}
}

Loading…
Cancel
Save