!148 修复项目启动时可能会造成es client must not be null的问题

Merge pull request !148 from OceansDeep/feature/pg
This commit is contained in:
OceansDeep 2022-04-22 01:13:07 +00:00 committed by Gitee
commit 363dbd3a7f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 7 additions and 19 deletions

View File

@ -16,7 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import javax.annotation.PreDestroy;
import java.io.IOException;
@ -69,11 +68,6 @@ public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {
return client;
}
@Bean("elasticsearchRestTemplate")
public ElasticsearchRestTemplate elasticsearchRestTemplate() {
return new ElasticsearchRestTemplate(this.client);
}
private HttpHost[] getHttpHosts() {
List<String> clusterNodes = elasticsearchProperties.getClusterNodes();
HttpHost[] httpHosts = new HttpHost[clusterNodes.size()];

View File

@ -14,10 +14,9 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
@ -42,8 +41,7 @@ public class SystemLogServiceImpl implements SystemLogService {
* ES
*/
@Autowired
@Qualifier("elasticsearchRestTemplate")
private ElasticsearchRestTemplate restTemplate;
private ElasticsearchOperations restTemplate;
@Override
public void saveLog(SystemLogVO systemLogVO) {

View File

@ -53,8 +53,7 @@ import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.mybatis.spring.MyBatisSystemException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchPage;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
@ -116,8 +115,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
@Autowired
private RocketmqCustomProperties rocketmqCustomProperties;
@Autowired
@Qualifier("elasticsearchRestTemplate")
private ElasticsearchRestTemplate restTemplate;
private ElasticsearchOperations restTemplate;
@Override
public void init() {

View File

@ -36,10 +36,9 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.SearchHitSupport;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.SearchPage;
@ -73,8 +72,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
* ES
*/
@Autowired
@Qualifier("elasticsearchRestTemplate")
private ElasticsearchRestTemplate restTemplate;
private ElasticsearchOperations restTemplate;
@Autowired
private EsGoodsIndexService esGoodsIndexService;