Skip to content

Commit 6dadac1

Browse files
committed
Merge branch 'gh-4895'
2 parents da45041 + 77e350a commit 6dadac1

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222

2323
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.beans.factory.annotation.Qualifier;
2425
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2627
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -42,14 +43,14 @@
4243
import org.springframework.context.event.ContextRefreshedEvent;
4344
import org.springframework.context.event.EventListener;
4445
import org.springframework.data.redis.core.RedisTemplate;
45-
import org.springframework.session.ExpiringSession;
4646
import org.springframework.util.StringUtils;
4747

4848
/**
4949
* {@link EnableAutoConfiguration Auto-configuration} for local development support.
5050
*
5151
* @author Phillip Webb
5252
* @author Andy Wilkinson
53+
* @author Vladimir Tsanev
5354
* @since 1.3.0
5455
*/
5556
@Configuration
@@ -164,12 +165,14 @@ private FileSystemWatcher newFileSystemWatcher() {
164165
}
165166

166167
@Configuration
167-
@ConditionalOnBean(name = "sessionRedisTemplate")
168+
@ConditionalOnBean(name = RedisRestartConfiguration.SESSION_REDIS_TEMPLATE_BEAN_NAME)
168169
static class RedisRestartConfiguration {
169170

171+
static final String SESSION_REDIS_TEMPLATE_BEAN_NAME = "sessionRedisTemplate";
172+
170173
@Bean
171174
public RestartCompatibleRedisSerializerConfigurer restartCompatibleRedisSerializerConfigurer(
172-
RedisTemplate<String, ExpiringSession> sessionRedisTemplate) {
175+
@Qualifier(SESSION_REDIS_TEMPLATE_BEAN_NAME) RedisTemplate<?, ?> sessionRedisTemplate) {
173176
return new RestartCompatibleRedisSerializerConfigurer(
174177
sessionRedisTemplate);
175178
}

spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RestartCompatibleRedisSerializerConfigurer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
2626
import org.springframework.data.redis.core.RedisTemplate;
2727
import org.springframework.data.redis.serializer.RedisSerializer;
2828
import org.springframework.data.redis.serializer.SerializationException;
29-
import org.springframework.session.ExpiringSession;
3029
import org.springframework.util.ObjectUtils;
3130

3231
/**
@@ -42,12 +41,11 @@
4241
*/
4342
class RestartCompatibleRedisSerializerConfigurer implements BeanClassLoaderAware {
4443

45-
private final RedisTemplate<String, ExpiringSession> redisTemplate;
44+
private final RedisTemplate<?, ?> redisTemplate;
4645

4746
private volatile ClassLoader classLoader;
4847

49-
RestartCompatibleRedisSerializerConfigurer(
50-
RedisTemplate<String, ExpiringSession> redisTemplate) {
48+
RestartCompatibleRedisSerializerConfigurer(RedisTemplate<?, ?> redisTemplate) {
5149
this.redisTemplate = redisTemplate;
5250
}
5351

spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,6 +68,7 @@
6868
*
6969
* @author Phillip Webb
7070
* @author Andy Wilkinson
71+
* @author Vladimir Tsanev
7172
*/
7273
public class LocalDevToolsAutoConfigurationTests {
7374

@@ -241,13 +242,27 @@ public void watchingAdditionalPaths() throws Exception {
241242
}
242243

243244
@Test
244-
public void sessionRedisTemplateIsConfiguredWithCustomDeserializers()
245+
public void sessionRedisTemplateIsConfiguredWithCustomDeserializers10()
245246
throws Exception {
246-
SpringApplication application = new SpringApplication(
247-
SessionRedisTemplateConfig.class, LocalDevToolsAutoConfiguration.class);
247+
sessionRedisTemplateIsConfiguredWithCustomDeserializers(
248+
Session10RedisTemplateConfig.class);
249+
}
250+
251+
@Test
252+
public void sessionRedisTemplateIsConfiguredWithCustomDeserializers11()
253+
throws Exception {
254+
sessionRedisTemplateIsConfiguredWithCustomDeserializers(
255+
Session11RedisTemplateConfig.class);
256+
}
257+
258+
private void sessionRedisTemplateIsConfiguredWithCustomDeserializers(
259+
Object sessionConfig) throws Exception {
260+
SpringApplication application = new SpringApplication(sessionConfig,
261+
LocalDevToolsAutoConfiguration.class);
248262
application.setWebEnvironment(false);
249263
this.context = application.run();
250-
RedisTemplate<?, ?> redisTemplate = this.context.getBean(RedisTemplate.class);
264+
RedisTemplate<?, ?> redisTemplate = this.context.getBean("sessionRedisTemplate",
265+
RedisTemplate.class);
251266
assertThat(redisTemplate.getHashKeySerializer(),
252267
is(instanceOf(RestartCompatibleRedisSerializer.class)));
253268
assertThat(redisTemplate.getHashValueSerializer(),
@@ -306,7 +321,7 @@ public static class WebResourcesConfig {
306321
}
307322

308323
@Configuration
309-
public static class SessionRedisTemplateConfig {
324+
public static class Session10RedisTemplateConfig {
310325

311326
@Bean
312327
public RedisTemplate<String, ExpiringSession> sessionRedisTemplate() {
@@ -317,4 +332,16 @@ public RedisTemplate<String, ExpiringSession> sessionRedisTemplate() {
317332

318333
}
319334

335+
@Configuration
336+
public static class Session11RedisTemplateConfig {
337+
338+
@Bean
339+
public RedisTemplate<Object, Object> sessionRedisTemplate() {
340+
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<Object, Object>();
341+
redisTemplate.setConnectionFactory(mock(RedisConnectionFactory.class));
342+
return redisTemplate;
343+
}
344+
345+
}
346+
320347
}

0 commit comments

Comments
 (0)