Skip to content

Commit

Permalink
Avoid conflicts with user provided RedisMessageListenerContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
vpavic committed Mar 29, 2019
1 parent 55102aa commit 094ffe8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public RedisOperationsSessionRepository sessionRepository() {
}

@Bean
public RedisMessageListenerContainer redisMessageListenerContainer(
public RedisMessageListenerContainer springSessionRedisMessageListenerContainer(
RedisOperationsSessionRepository sessionRepository) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(this.redisConnectionFactory);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2019 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.
Expand All @@ -16,6 +16,7 @@

package org.springframework.session.data.redis.config.annotation.web.http;

import java.util.Map;
import java.util.Properties;

import org.junit.After;
Expand All @@ -31,6 +32,7 @@
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.session.data.redis.RedisOperationsSessionRepository;
import org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory;
Expand Down Expand Up @@ -190,6 +192,17 @@ public void multipleConnectionFactoryRedisConfig() {
.withMessageContaining("expected single matching bean but found 2");
}

@Test // gh-1252
public void customRedisMessageListenerContainerConfig() {
registerAndRefresh(RedisConfig.class,
CustomRedisMessageListenerContainerConfig.class);
Map<String, RedisMessageListenerContainer> beans = this.context
.getBeansOfType(RedisMessageListenerContainer.class);
assertThat(beans).hasSize(2);
assertThat(beans).containsKeys("springSessionRedisMessageListenerContainer",
"redisMessageListenerContainer");
}

private void registerAndRefresh(Class<?>... annotatedClasses) {
this.context.register(annotatedClasses);
this.context.refresh();
Expand Down Expand Up @@ -314,4 +327,15 @@ static class CustomRedisHttpSessionConfiguration2 {

}

@Configuration
@EnableRedisHttpSession
static class CustomRedisMessageListenerContainerConfig {

@Bean
public RedisMessageListenerContainer redisMessageListenerContainer() {
return new RedisMessageListenerContainer();
}

}

}

0 comments on commit 094ffe8

Please sign in to comment.