From 6ec34c114cc3f0841c228fa3f5f2fa67bf21dc8f Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 5 Oct 2017 18:41:34 -0400 Subject: [PATCH] INT-4354: Add beanClassLoader support to RedisMS JIRA: https://jira.spring.io/browse/INT-4354 It's hard to test different ClassLoader in unit tests, so the fix comes without them **Cherry-pick to 4.3.x** --- .../integration/redis/store/RedisMessageStore.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisMessageStore.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisMessageStore.java index 20c79248fb..18bcd8432c 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisMessageStore.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisMessageStore.java @@ -19,6 +19,7 @@ package org.springframework.integration.redis.store; import java.util.Collection; import java.util.Set; +import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.BoundValueOperations; import org.springframework.data.redis.core.RedisTemplate; @@ -40,10 +41,12 @@ import org.springframework.util.Assert; * * @since 2.1 */ -public class RedisMessageStore extends AbstractKeyValueMessageStore { +public class RedisMessageStore extends AbstractKeyValueMessageStore implements BeanClassLoaderAware { private final RedisTemplate redisTemplate; + private boolean valueSerializerSet; + /** * Construct {@link RedisMessageStore} based on the provided * {@link RedisConnectionFactory} and default empty prefix. @@ -71,9 +74,17 @@ public class RedisMessageStore extends AbstractKeyValueMessageStore { this.redisTemplate.afterPropertiesSet(); } + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + if (!this.valueSerializerSet) { + this.redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer(classLoader)); + } + } + public void setValueSerializer(RedisSerializer valueSerializer) { Assert.notNull(valueSerializer, "'valueSerializer' must not be null"); this.redisTemplate.setValueSerializer(valueSerializer); + this.valueSerializerSet = true; } @Override