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);
}
} }

【Spring】Springboot监听器,启动之后初始化工作的更多相关文章

  1. springboot项目启动之后初始化自定义配置类

    前言 今天在写项目的时候,需要再springboot项目启动之后,加载我自定义的配置类的一些方法,百度了之后特此记录下. 正文 方法有两种: 1. 创建自定义类实现 CommandLineRunner ...

  2. SpringBoot 源码解析 (三)----- Spring Boot 精髓:启动时初始化数据

    在我们用 springboot 搭建项目的时候,有时候会碰到在项目启动时初始化一些操作的需求 ,针对这种需求 spring boot为我们提供了以下几种方案供我们选择: ApplicationRunn ...

  3. SpringBoot IoC启动流程、初始化过程及Bean生命周期各个阶段的作用

    目录 SpringBoot IoC启动流程.初始化过程及Bean生命周期各个阶段的作用 简述 首先明确IoC容器是啥 准备-SpringApplication的实例化 启动-SpringApplica ...

  4. 让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean

    让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean 问题描述 实现思路 思路一 [不符合要求] 思路二[满足要求] 思路三[未试验] 问题描述 目前我工作环境下,后端主要的框架 ...

  5. Spring源码解析之:Spring Security启动细节和工作模式--转载

    原文地址:http://blog.csdn.net/bluishglc/article/details/12709557 Spring-Security的启动加载细节   Spring-Securit ...

  6. 【Spring】DispatcherServlet的启动和初始化

    使用过SpringMVC的都知道DispatcherServlet,下面介绍下该Servlet的启动与初始化.作为Servlet,DispatcherServlet的启动与Serlvet的启动过程是相 ...

  7. Spring Boot 2 (七):Spring Boot 如何解决项目启动时初始化资源

    Spring Boot 2 (七):Spring Boot 如何解决项目启动时初始化资源 在项目启动的时候需要做一些初始化的操作,比如初始化线程池,提前加载好加密证书等.今天就给大家介绍一个 Spri ...

  8. Spring IOC容器启动流程源码解析(四)——初始化单实例bean阶段

    目录 1. 引言 2. 初始化bean的入口 3 尝试从当前容器及其父容器的缓存中获取bean 3.1 获取真正的beanName 3.2 尝试从当前容器的缓存中获取bean 3.3 从父容器中查找b ...

  9. Tomcat启动时加载数据到缓存---web.xml中listener加载顺序(例如顺序:1、初始化spring容器,2、初始化线程池,3、加载业务代码,将数据库中数据加载到内存中)

    最近公司要做功能迁移,原来的后台使用的Netty,现在要迁移到在uap上,也就是说所有后台的代码不能通过netty写的加载顺序加载了. 问题就来了,怎样让迁移到tomcat的代码按照原来的加载顺序进行 ...

随机推荐

  1. Python学习(二十) —— 前端之CSS

    转载自http://www.cnblogs.com/liwenzhou/p/7999532.html 一.CSS介绍 CSS(Cascading Style Sheet,层叠样式表)定义如何显示HTM ...

  2. html5的audio实现高仿微信语音播放效果

    效果图 前台大体呈现效果图如下: 点击就可以播放mp3格式的录音.点击另外一个录音,当前录音停止! 思路 关于播放动画,这个很简单,我们可以用css3的逐帧动画来实现.关于逐帧动画,我之前的文章也写过 ...

  3. c#生成连续单号

    bill.BillCode = GetBillCode("JH");//生成单号 if (bill.BillCode == "no") { bill.BillC ...

  4. 01. Numpy模块

    1.科学计算工具-Numpy基础数据结构 1.1.数组ndarray的属性 NumPy数组是一个多维数组对象,称为ndarray.其由两部分组成:① 实际的数据② 描述这些数据的元数据 注意数组格式, ...

  5. CodeSignal 刷题 —— matrixElementSum

    After they became famous, the CodeBots all decided to move to a new building and live together. The ...

  6. centos7下docker启动失败解决

    docker启动失败解决 could not change group /var/run/docker.sock to docker: gr... not found 如果出现:Job for doc ...

  7. Web服务API

    Web服务API     内容 [ 隐藏 ]  1 概述 2个 services.php 3 详细教程 4 例子 5 另见 概观 Web服务API允许您将插件的功能(通常是外部函数)公开为Web服务. ...

  8. POJ-1679 The Unique MST (判断最小生成树的唯一性)

    <题目链接> 题目大意: 给定一张无向图,判断其最小生成树是否唯一. 解题分析: 对图中每条边,扫描其它边,如果存在相同权值的边,则标记该边:用kruskal求出MST. 如果MST中无标 ...

  9. 现代C++之理解模板类型推断(template type deduction)

    理解模板类型推断(template type deduction) 我们往往不能理解一个复杂的系统是如何运作的,但是却知道这个系统能够做什么.C++的模板类型推断便是如此,把参数传递到模板函数往往能让 ...

  10. linux 进阶命令

    进阶命令 1    df指令   查看磁盘的空间 # df -h    -h表示可读性更高,方便读取 执行指令后(Filesystem:磁盘名称  size:磁盘总大小  Used: 被使用的大小  ...