Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-4354

RedisMessageStore uses incorrect classloader

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Complete
    • 4.3.12
    • 5.0 RC1, 4.3.13
    • Redis Support
    • Redis and RabbitMQ

    Description

      RedisMessageStore uses the default CL rather than the one from BeanFactory when creating the value serializer:
      this.redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());

      This results in ClassCastExceptions for deserialized instances from the message store:
      Caused by: org.springframework.messaging.MessageHandlingException: nested exception is java.lang.ClassCastException: org.sdf.rkm.aggex.domain.TimeResponse cannot be cast to org.sdf.rkm.aggex.domain.TimeResponse

      The following workaround is recommended:

      public class PipelineConfig implements BeanClassLoaderAware {
          private ClassLoader classLoader;
      
          @Override
          public void setBeanClassLoader(ClassLoader classLoader) {
              this.classLoader = classLoader;
          }
      
         @Bean
          public MessageGroupStore messageGroupStore(RedisConnectionFactory redisConnectionFactory) {
              RedisMessageStore messageStore = new RedisMessageStore(redisConnectionFactory, "your-prefix-here");
              messageStore.setValueSerializer(new JdkSerializationRedisSerializer(this.classLoader));
              return messageStore;
          }
      }
      

      See also Gitter chat from Oct 3-4, 2017 .

      Attachments

        Activity

          People

            abilan Artem Bilan
            robmoore Rob Moore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: