71
71
import org .elasticsearch .search .sort .SortOrder ;
72
72
import org .slf4j .Logger ;
73
73
import org .slf4j .LoggerFactory ;
74
+ import org .springframework .beans .BeansException ;
75
+ import org .springframework .context .ApplicationContext ;
76
+ import org .springframework .context .ApplicationContextAware ;
74
77
import org .springframework .core .io .ClassPathResource ;
75
78
import org .springframework .data .domain .Page ;
76
79
import org .springframework .data .domain .Sort ;
95
98
* @author Artur Konczak
96
99
*/
97
100
98
- public class ElasticsearchTemplate implements ElasticsearchOperations {
101
+ public class ElasticsearchTemplate implements ElasticsearchOperations , ApplicationContextAware {
99
102
100
103
private static final Logger logger = LoggerFactory .getLogger (ElasticsearchTemplate .class );
101
104
private Client client ;
@@ -120,8 +123,8 @@ public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearch
120
123
121
124
public ElasticsearchTemplate (Client client , ElasticsearchConverter elasticsearchConverter , ResultsMapper resultsMapper ) {
122
125
this .client = client ;
123
- this .elasticsearchConverter = (elasticsearchConverter == null ) ? new MappingElasticsearchConverter (
124
- new SimpleElasticsearchMappingContext ()) : elasticsearchConverter ;
126
+ this .elasticsearchConverter = (elasticsearchConverter == null ) ? new MappingElasticsearchConverter (
127
+ new SimpleElasticsearchMappingContext ()) : elasticsearchConverter ;
125
128
this .resultsMapper = (resultsMapper == null ) ? new DefaultResultMapper (this .elasticsearchConverter .getMappingContext ()) : resultsMapper ;
126
129
}
127
130
@@ -873,7 +876,14 @@ private List<String> extractIds(SearchResponse response) {
873
876
return ids ;
874
877
}
875
878
876
- private static String [] toArray (List <String > values ) {
879
+ @ Override
880
+ public void setApplicationContext (ApplicationContext context ) throws BeansException {
881
+ if (elasticsearchConverter instanceof ApplicationContextAware ){
882
+ ((ApplicationContextAware )elasticsearchConverter ).setApplicationContext (context );
883
+ }
884
+ }
885
+
886
+ private static String [] toArray (List <String > values ) {
877
887
String [] valuesAsArray = new String [values .size ()];
878
888
return values .toArray (valuesAsArray );
879
889
}
0 commit comments