29
29
import org .springframework .data .elasticsearch .annotations .Setting ;
30
30
import org .springframework .data .mapping .model .BasicPersistentEntity ;
31
31
import org .springframework .data .util .TypeInformation ;
32
+ import org .springframework .expression .Expression ;
33
+ import org .springframework .expression .ParserContext ;
34
+ import org .springframework .expression .spel .standard .SpelExpressionParser ;
32
35
import org .springframework .expression .spel .support .StandardEvaluationContext ;
33
36
import org .springframework .util .Assert ;
34
37
@@ -43,6 +46,8 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
43
46
implements ElasticsearchPersistentEntity <T >, ApplicationContextAware {
44
47
45
48
private final StandardEvaluationContext context ;
49
+ private final SpelExpressionParser parser ;
50
+
46
51
private String indexName ;
47
52
private String indexType ;
48
53
private short shards ;
@@ -56,6 +61,8 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
56
61
public SimpleElasticsearchPersistentEntity (TypeInformation <T > typeInformation ) {
57
62
super (typeInformation );
58
63
this .context = new StandardEvaluationContext ();
64
+ this .parser = new SpelExpressionParser ();
65
+
59
66
Class <T > clazz = typeInformation .getType ();
60
67
if (clazz .isAnnotationPresent (Document .class )) {
61
68
Document document = clazz .getAnnotation (Document .class );
@@ -82,7 +89,8 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
82
89
83
90
@ Override
84
91
public String getIndexName () {
85
- return indexName ;
92
+ Expression expression = parser .parseExpression (indexName , ParserContext .TEMPLATE_EXPRESSION );
93
+ return expression .getValue (context , String .class );
86
94
}
87
95
88
96
@ Override
0 commit comments