File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
main/java/org/springframework/data/redis/repository/configuration
test/java/org/springframework/data/redis/repository Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 27
27
import org .springframework .context .annotation .Import ;
28
28
import org .springframework .data .keyvalue .core .KeyValueOperations ;
29
29
import org .springframework .data .keyvalue .repository .config .QueryCreatorType ;
30
+ import org .springframework .data .redis .core .RedisOperations ;
30
31
import org .springframework .data .redis .core .index .IndexConfiguration ;
31
32
import org .springframework .data .redis .repository .query .RedisQueryCreator ;
32
33
import org .springframework .data .redis .repository .support .RedisRepositoryFactoryBean ;
127
128
*/
128
129
boolean considerNestedRepositories () default false ;
129
130
131
+ /**
132
+ * Configures the bean name of the {@link RedisOperations} to be used. Defaulted to {@literal redisTemplate}.
133
+ *
134
+ * @return
135
+ */
136
+ String redisTemplateRef () default "redisTemplate" ;
137
+
130
138
/**
131
139
* TODO: explain configuration options
132
140
*
Original file line number Diff line number Diff line change 17
17
18
18
import org .springframework .beans .DirectFieldAccessor ;
19
19
import org .springframework .beans .factory .config .ConstructorArgumentValues ;
20
+ import org .springframework .beans .factory .config .RuntimeBeanReference ;
20
21
import org .springframework .beans .factory .support .AbstractBeanDefinition ;
21
22
import org .springframework .beans .factory .support .GenericBeanDefinition ;
22
23
import org .springframework .beans .factory .support .RootBeanDefinition ;
25
26
import org .springframework .data .keyvalue .repository .config .KeyValueRepositoryConfigurationExtension ;
26
27
import org .springframework .data .redis .core .RedisKeyValueAdapter ;
27
28
import org .springframework .data .repository .config .RepositoryConfigurationSource ;
29
+ import org .springframework .util .StringUtils ;
28
30
29
31
/**
30
32
* @author Christoph Strobl
@@ -75,6 +77,14 @@ protected AbstractBeanDefinition getDefaultKeyValueTemplateBeanDefinition(
75
77
indexConfiguration .setBeanClass (aa .getClass ("indexConfiguration" ));
76
78
77
79
ConstructorArgumentValues constructorArgumentValuesForRedisKeyValueAdapter = new ConstructorArgumentValues ();
80
+
81
+ String redisTemplateRef = configurationSource .getAttribute ("redisTemplateRef" );
82
+ if (StringUtils .hasText (redisTemplateRef )) {
83
+
84
+ constructorArgumentValuesForRedisKeyValueAdapter .addGenericArgumentValue (new RuntimeBeanReference (
85
+ redisTemplateRef ));
86
+ }
87
+
78
88
constructorArgumentValuesForRedisKeyValueAdapter .addGenericArgumentValue (indexConfiguration );
79
89
redisKeyValueAdapterDefinition .setConstructorArgumentValues (constructorArgumentValuesForRedisKeyValueAdapter );
80
90
Original file line number Diff line number Diff line change 29
29
import org .junit .Test ;
30
30
import org .junit .runner .RunWith ;
31
31
import org .springframework .beans .factory .annotation .Autowired ;
32
+ import org .springframework .context .annotation .Bean ;
32
33
import org .springframework .context .annotation .Configuration ;
33
34
import org .springframework .data .annotation .Id ;
34
35
import org .springframework .data .annotation .Reference ;
35
36
import org .springframework .data .keyvalue .annotation .KeySpace ;
36
37
import org .springframework .data .keyvalue .core .KeyValueTemplate ;
38
+ import org .springframework .data .redis .connection .jedis .JedisConnectionFactory ;
39
+ import org .springframework .data .redis .core .RedisTemplate ;
37
40
import org .springframework .data .redis .core .index .IndexConfiguration ;
38
41
import org .springframework .data .redis .core .index .Indexed ;
39
42
import org .springframework .data .redis .core .index .RedisIndexDefinition ;
@@ -53,6 +56,18 @@ public class RedisRepositoryIntegrationTests {
53
56
@ EnableRedisRepositories (considerNestedRepositories = true , indexConfiguration = MyIndexConfiguration .class )
54
57
static class Config {
55
58
59
+ @ Bean
60
+ RedisTemplate <?, ?> redisTemplate () {
61
+
62
+ JedisConnectionFactory connectionFactory = new JedisConnectionFactory ();
63
+ connectionFactory .afterPropertiesSet ();
64
+
65
+ RedisTemplate <byte [], byte []> template = new RedisTemplate <byte [], byte []>();
66
+ template .setConnectionFactory (connectionFactory );
67
+
68
+ return template ;
69
+ }
70
+
56
71
}
57
72
58
73
@ Autowired PersonRepository repo ;
You can’t perform that action at this time.
0 commit comments