mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 02:46:50 +08:00
36 lines
1.2 KiB
Java
36 lines
1.2 KiB
Java
package com.xboe.config;
|
||
|
||
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||
import org.springframework.context.event.EventListener;
|
||
import org.springframework.stereotype.Component;
|
||
|
||
/**
|
||
* ElasticSearch索引初始化器
|
||
* 在Spring Boot启动完成并监听到配置文件加载完毕后,检查并创建所需的ES索引
|
||
*
|
||
* @author AI Assistant
|
||
*/
|
||
@Slf4j
|
||
@Component
|
||
public class ElasticSearchIndexInitializer {
|
||
|
||
@Autowired
|
||
private IElasticSearchIndexService elasticSearchIndexService;
|
||
|
||
/**
|
||
* 监听Spring Boot应用启动完成事件
|
||
* ApplicationReadyEvent在应用启动完成、所有配置加载完毕后触发
|
||
*/
|
||
@EventListener(ApplicationReadyEvent.class)
|
||
public void initializeElasticSearchIndices() {
|
||
if (elasticSearchIndexService.checkIndexExists()) {
|
||
log.info("ElasticSearch索引 ai_chat_messages 已存在");
|
||
} else {
|
||
log.info("ElasticSearch索引 ai_chat_messages 不存在,开始创建...");
|
||
elasticSearchIndexService.createIndex();
|
||
}
|
||
}
|
||
} |