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);
            }
        }
        
    }
  • 相关阅读:
    [转] Akka实战:构建REST风格的微服务
    [转] Node.js的线程和进程
    [转] Spring Integration 系统集成
    NodeJS使用SSL证书
    Tomcat SSL证书安装配置
    [转]【NODE】用WS模块创建加密的WS服务(WSS)
    [转] Spring Boot实战之Filter实现使用JWT进行接口认证
    [转] 前后端分离之JWT用户认证
    [转] 使用 Java8 Optional 的正确姿势
    [转] SpringBoot RESTful 应用中的异常处理小结
  • 原文地址:https://www.cnblogs.com/junneyang/p/9132779.html
Copyright © 2011-2022 走看看