1+ package com .redis .om .spring .annotations .hash ;
2+
3+ import com .redis .om .spring .AbstractBaseEnhancedRedisTest ;
4+ import com .redis .om .spring .fixtures .hash .model .Issue322User ;
5+ import com .redis .om .spring .fixtures .hash .repository .Issue322UserRepository ;
6+
7+ import org .junit .jupiter .api .Test ;
8+ import org .junit .jupiter .api .BeforeEach ;
9+ import org .springframework .beans .factory .annotation .Autowired ;
10+ import org .springframework .data .redis .core .RedisTemplate ;
11+ import org .springframework .context .annotation .Bean ;
12+ import org .springframework .context .annotation .Configuration ;
13+ import org .springframework .context .annotation .Import ;
14+ import org .springframework .data .redis .connection .RedisConnectionFactory ;
15+
16+ import static org .assertj .core .api .Assertions .assertThat ;
17+
18+ /**
19+ * Test to verify issue #322 is resolved: @EnableRedisEnhancedRepositories creating bean
20+ * with potential ambiguous RedisOperations beans.
21+ *
22+ * This test verifies that enhanced repositories work correctly even when multiple
23+ * RedisTemplate beans are present in the application context.
24+ */
25+ @ Import (Issue322TestContainerBeanCreationTest .AdditionalRedisConfig .class )
26+ public class Issue322TestContainerBeanCreationTest extends AbstractBaseEnhancedRedisTest {
27+
28+ @ Autowired
29+ private Issue322UserRepository userRepository ;
30+
31+ @ Autowired (required = false )
32+ private RedisTemplate <String , String > stringRedisTemplate ;
33+
34+ @ Autowired
35+ private RedisTemplate <Object , Object > redisTemplate ;
36+
37+ @ BeforeEach
38+ void setup () {
39+ userRepository .deleteAll ();
40+ }
41+
42+ @ Test
43+ void testRepositoryBeanCreationWithMultipleRedisTemplates () {
44+ // This test verifies that the repository bean is created successfully
45+ // even when multiple RedisTemplate beans are available
46+ assertThat (userRepository ).isNotNull ();
47+
48+ // Verify that multiple Redis templates can coexist
49+ assertThat (stringRedisTemplate ).isNotNull ();
50+ assertThat (redisTemplate ).isNotNull ();
51+
52+ // Test basic repository functionality
53+ Issue322User user = new Issue322User ();
54+ user .setFirstName ("TestFirst" );
55+ user .setLastName ("TestLast" );
56+ user .
setEmail (
"[email protected] " );
57+
58+ Issue322User savedUser = userRepository .save (user );
59+ assertThat (savedUser ).isNotNull ();
60+ assertThat (savedUser .getId ()).isNotNull ();
61+
62+ // Verify we can find the user
63+ assertThat (userRepository .findById (savedUser .getId ())).isPresent ();
64+
65+ // Test finding by indexed field
66+ assertThat (
userRepository .
findByEmail (
"[email protected] " )).
isPresent ();
67+ }
68+
69+ @ Configuration
70+ static class AdditionalRedisConfig {
71+
72+ // Create a secondary RedisTemplate that could potentially cause ambiguity
73+ // This simulates the scenario described in issue #322 where multiple
74+ // RedisTemplate beans exist
75+ @ Bean
76+ public RedisTemplate <String , String > stringRedisTemplate (RedisConnectionFactory connectionFactory ) {
77+ RedisTemplate <String , String > template = new RedisTemplate <>();
78+ template .setConnectionFactory (connectionFactory );
79+ template .afterPropertiesSet ();
80+ return template ;
81+ }
82+ }
83+ }
0 commit comments