Browse Source

优化elasticsearch 关闭逻辑

zhou-hao 5 years ago
parent
commit
396ef0142d

+ 2 - 2
jetlinks-components/elasticsearch-component/src/main/java/org/jetlinks/community/elastic/search/configuration/ElasticSearchConfiguration.java

@@ -52,8 +52,8 @@ public class ElasticSearchConfiguration {
         return new ElasticRestClient(client, client);
     }
 
-    @Bean
-    public RestHighLevelClient elasticsearchRestHighLevelClient(ElasticRestClient client) {
+    @Bean(destroyMethod = "close")
+    public RestHighLevelClient restHighLevelClient(ElasticRestClient client) {
         return client.getWriteClient();
     }
 

+ 2 - 0
jetlinks-components/elasticsearch-component/src/main/java/org/jetlinks/community/elastic/search/service/DefaultElasticSearchService.java

@@ -27,6 +27,7 @@ import org.jetlinks.community.elastic.search.index.ElasticSearchIndexManager;
 import org.jetlinks.community.elastic.search.utils.ElasticSearchConverter;
 import org.jetlinks.community.elastic.search.utils.ReactorActionListener;
 import org.reactivestreams.Publisher;
+import org.springframework.context.annotation.DependsOn;
 import org.springframework.stereotype.Service;
 import reactor.core.publisher.BufferOverflowStrategy;
 import reactor.core.publisher.Flux;
@@ -47,6 +48,7 @@ import java.util.stream.Collectors;
  **/
 @Service
 @Slf4j
+@DependsOn("restHighLevelClient")
 public class DefaultElasticSearchService implements ElasticSearchService {
 
     private final ElasticRestClient restClient;

+ 3 - 1
jetlinks-standalone/src/main/java/org/jetlinks/community/standalone/JetLinksApplication.java

@@ -8,6 +8,7 @@ import org.hswebframework.web.loggin.aop.EnableAccessLogger;
 import org.hswebframework.web.logging.events.AccessLoggerAfterEvent;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.context.annotation.Profile;
@@ -18,7 +19,8 @@ import javax.annotation.PostConstruct;
 
 
 @SpringBootApplication(scanBasePackages = "org.jetlinks.community", exclude = {
-    DataSourceAutoConfiguration.class
+    DataSourceAutoConfiguration.class,
+    RestClientAutoConfiguration.class
 })
 @EnableCaching
 @EnableEasyormRepository("org.jetlinks.community.**.entity")