diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index e4e156742f..ff5c8ac008 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -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 sessionRedisTemplate) { + @Qualifier(SESSION_REDIS_TEMPLATE_BEAN_NAME) RedisTemplate sessionRedisTemplate) { return new RestartCompatibleRedisSerializerConfigurer( sessionRedisTemplate); } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RestartCompatibleRedisSerializerConfigurer.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RestartCompatibleRedisSerializerConfigurer.java index c45172f7b1..6b4b0914fa 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RestartCompatibleRedisSerializerConfigurer.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RestartCompatibleRedisSerializerConfigurer.java @@ -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 redisTemplate; + private final RedisTemplate redisTemplate; private volatile ClassLoader classLoader; - RestartCompatibleRedisSerializerConfigurer( - RedisTemplate redisTemplate) { + RestartCompatibleRedisSerializerConfigurer(RedisTemplate redisTemplate) { this.redisTemplate = redisTemplate; } diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java index f3b5a1ee8b..7f2c0ed9d5 100755 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java @@ -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 sessionRedisTemplate() { @@ -317,4 +332,16 @@ public class LocalDevToolsAutoConfigurationTests { } + @Configuration + public static class Session11RedisTemplateConfig { + + @Bean + public RedisTemplate sessionRedisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate(); + redisTemplate.setConnectionFactory(mock(RedisConnectionFactory.class)); + return redisTemplate; + } + + } + }