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);
            }
        }
        
    }
  • 相关阅读:
    POJ3709 K-Anonymous Sequence 斜率优化DP
    POJ3233 Matrix Power Series
    第六周 Leetcode 446. Arithmetic Slices II
    POJ1743 Musical Theme 最长重复子串 利用后缀数组
    Ural 1517. Freedom of Choice 后缀数组
    iOS跳转到另一个程序
    上传源码到github
    NSTimer用法,暂停,继续,初始化
    iOS中多线程原理与runloop介绍
    NSRunLoop 概述和原理
  • 原文地址:https://www.cnblogs.com/junneyang/p/9132779.html
Copyright © 2011-2022 走看看