zoukankan      html  css  js  c++  java
  • 【Spring】Springboot监听器,启动之后初始化工作

    package com.laplace.laplace.common.starter.config;

    import java.io.IOException;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.context.event.ApplicationReadyEvent;
    import org.springframework.context.ApplicationListener;
    import org.springframework.stereotype.Component;

    /*
    * http://blog.netgloo.com/2014/11/13/run-code-at-spring-boot-startup/
    * http://www.baeldung.com/running-setup-logic-on-startup-in-spring
    * https://springframework.guru/running-code-on-spring-boot-startup/
    */
    @Component
    public class ApplicationStartup implements ApplicationListener<ApplicationReadyEvent>{
    private static final Logger LOG = LoggerFactory.getLogger(ApplicationStartup.class);

    @Autowired
    private GrpcLocalProxyService grpcLocalProxyService;

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
    if (grpcLocalProxyService == null) {
    LOG.info("grpcLocalProxyService is null/disabled, no need to loadProtoResources");
    }
    try {
    grpcLocalProxyService.loadProtoResources();
    } catch (IOException | ClassNotFoundException e) {
    LOG.error("grpcLocalProxyService loadProtoResources exception, {}", e);
    }
    }

    }

    package com.laplace.laplace.common.starter.config;
    
    import java.io.IOException;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.context.event.ApplicationReadyEvent;
    import org.springframework.context.ApplicationListener;
    import org.springframework.stereotype.Component;
    
    /*
     * http://blog.netgloo.com/2014/11/13/run-code-at-spring-boot-startup/
     * http://www.baeldung.com/running-setup-logic-on-startup-in-spring
     * https://springframework.guru/running-code-on-spring-boot-startup/
    */    
    @Component
    public class ApplicationStartup implements ApplicationListener<ApplicationReadyEvent>{
        private static final Logger LOG = LoggerFactory.getLogger(ApplicationStartup.class);
        
        @Autowired
        private GrpcLocalProxyService grpcLocalProxyService;
        
    
        @Override
        public void onApplicationEvent(ApplicationReadyEvent event) {
            if (grpcLocalProxyService == null) {
                LOG.info("grpcLocalProxyService is null/disabled, no need to loadProtoResources");
            } 
            try {
                grpcLocalProxyService.loadProtoResources();
            } catch (IOException | ClassNotFoundException e) {
                LOG.error("grpcLocalProxyService loadProtoResources exception, {}", e);
            }
        }
        
    }
  • 相关阅读:
    [BZOJ4825][HNOI2017]单旋(线段树+Splay)
    [BZOJ4542][HNOI2016]大数(莫队)
    [LOJ6281]数列分块入门 5
    [LOJ6280]数列分块入门 4
    [LOJ6279]数列分块入门 3
    [LOJ6278]数列分块入门 2
    [LOJ6277]数列分块入门 1
    [BZOJ2120]数颜色
    [BZOJ3585]mex
    [ZJb417]区间众数
  • 原文地址:https://www.cnblogs.com/junneyang/p/9132779.html
Copyright © 2011-2022 走看看