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);
            }
        }
        
    }
  • 相关阅读:
    <context-param>与<init-param>的区别与作用(转自青春乐园)(
    使用Derby ij客户端工具
    转载 Ofbiz 入门教程
    数据库中插入和读取图片
    事务的使用
    存储过程
    触发器 的使用
    JS面试题及答案
    课程主页面三个接口开发
    增加media文件配置
  • 原文地址:https://www.cnblogs.com/junneyang/p/9132779.html
Copyright © 2011-2022 走看看