peng
2026-03-18 e59a0201057ba67cad425fed804c82ff4ba0c6f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.tievd.cube.modules.system.listener;
 
import com.tievd.cube.modules.system.service.ISysGatewayRouteService;
import lombok.extern.slf4j.Slf4j;
import com.tievd.cube.commons.constant.CacheConst;
import com.tievd.cube.application.config.condition.CloudModeCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Conditional;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
 
/**
 * 启动程序,初始化路由配置
 *
 * @author flyme
 * @version 1.1.2
 * @since 2020-11-22
 */
@Slf4j
@Component
@Conditional(CloudModeCondition.class)
public class SystemInitListener implements ApplicationListener<ApplicationReadyEvent>, Ordered {
 
    @Autowired
    private ISysGatewayRouteService sysGatewayRouteService;
 
    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        log.info("服务已启动,初始化路由配置!");
        if (applicationReadyEvent.getApplicationContext().getDisplayName().contains("AnnotationConfigServletWebServerApplicationContext")) {
            sysGatewayRouteService.addRoute2Redis(CacheConst.GATEWAY_ROUTES);
        }
    }
 
    @Override
    public int getOrder() {
        return 1;
    }
}