Files
java-servers/servers/boe-server-all/src/main/java/com/xboe/config/ElasticSearchIndexInitializer.java

36 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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();
}
}
}