【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);
}
} }
【Spring】Springboot监听器,启动之后初始化工作的更多相关文章
- springboot项目启动之后初始化自定义配置类
前言 今天在写项目的时候,需要再springboot项目启动之后,加载我自定义的配置类的一些方法,百度了之后特此记录下. 正文 方法有两种: 1. 创建自定义类实现 CommandLineRunner ...
- SpringBoot 源码解析 (三)----- Spring Boot 精髓:启动时初始化数据
在我们用 springboot 搭建项目的时候,有时候会碰到在项目启动时初始化一些操作的需求 ,针对这种需求 spring boot为我们提供了以下几种方案供我们选择: ApplicationRunn ...
- SpringBoot IoC启动流程、初始化过程及Bean生命周期各个阶段的作用
目录 SpringBoot IoC启动流程.初始化过程及Bean生命周期各个阶段的作用 简述 首先明确IoC容器是啥 准备-SpringApplication的实例化 启动-SpringApplica ...
- 让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean
让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean 问题描述 实现思路 思路一 [不符合要求] 思路二[满足要求] 思路三[未试验] 问题描述 目前我工作环境下,后端主要的框架 ...
- Spring源码解析之:Spring Security启动细节和工作模式--转载
原文地址:http://blog.csdn.net/bluishglc/article/details/12709557 Spring-Security的启动加载细节 Spring-Securit ...
- 【Spring】DispatcherServlet的启动和初始化
使用过SpringMVC的都知道DispatcherServlet,下面介绍下该Servlet的启动与初始化.作为Servlet,DispatcherServlet的启动与Serlvet的启动过程是相 ...
- Spring Boot 2 (七):Spring Boot 如何解决项目启动时初始化资源
Spring Boot 2 (七):Spring Boot 如何解决项目启动时初始化资源 在项目启动的时候需要做一些初始化的操作,比如初始化线程池,提前加载好加密证书等.今天就给大家介绍一个 Spri ...
- Spring IOC容器启动流程源码解析(四)——初始化单实例bean阶段
目录 1. 引言 2. 初始化bean的入口 3 尝试从当前容器及其父容器的缓存中获取bean 3.1 获取真正的beanName 3.2 尝试从当前容器的缓存中获取bean 3.3 从父容器中查找b ...
- Tomcat启动时加载数据到缓存---web.xml中listener加载顺序(例如顺序:1、初始化spring容器,2、初始化线程池,3、加载业务代码,将数据库中数据加载到内存中)
最近公司要做功能迁移,原来的后台使用的Netty,现在要迁移到在uap上,也就是说所有后台的代码不能通过netty写的加载顺序加载了. 问题就来了,怎样让迁移到tomcat的代码按照原来的加载顺序进行 ...
随机推荐
- UOJ#23. 【UR #1】跳蚤国王下江南 仙人掌 Tarjan 点双 圆方树 点分治 多项式 FFT
原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ23.html 题目传送门 - UOJ#23 题意 给定一个有 n 个节点的仙人掌(可能有重边). 对于所有 ...
- POJ3074 Sudoku 舞蹈链 DLX
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目(传送门) 题意概括 给出一个残缺的数独,求解. 题解 DLX + 矩阵构建 (两个传送门) 代码 #include & ...
- ES6 系列之 defineProperty 与 proxy
,, ; ; ; } ; }); }; ; }); } });
- SVM:随机产生100个点,建立模型,找出超平面方程——Jaosn niu
import numpy as np import pylab as pl from sklearn import svm # we create 40 separable points #np.ra ...
- Android Studio项目生成Jar包
步骤: 1)在module的gradle文件中,将apply plugin:'com.android.application'改为apply plugin:'com.android.library' ...
- python 数据结构之二叉树
二叉树关键在构建和遍历,python实现相对简单,我们在实现需要用到类,分别设置爱左右子树,根节点,然后从根进行遍历,进行判断,若为空进行树的构建,非空则返回到列表中即可,我在进行遍历时产生了一个错误 ...
- UVA 1590 IP Networks JAVA
题意:输入m代表接下来的数据个数,计算接下来输入数据的网络掩码,和最小网络地址. 思路:①子网掩码:先将数据转为二进制,判断从哪一位开始有数据不一样,记下下标index,则子网掩码是index的前面是 ...
- 如何突破Ue4材质编辑器没有Pass的概念
Content-Driven Multipass Rendering in UE4 GDC 2017 Blueprint Drawing to Render Targets Overview Live ...
- 潭州课堂25班:Ph201805201 django框架 第三课 模板路径,变量,过滤器,静态文件的引用 (课堂笔记)
第二种方法 首先 'APP_DIRS': True, 将 app 的名字在 INSTALLED_APPS 进行注册 模板变量 传的各种数据类型,和取值 过渡器: 静态文件: 在项目文件目录 中创建 ...
- STM32点亮闪烁LED灯
详解请看其他博客: http://www.cnblogs.com/whik/p/6672730.html http://www.51hei.com/bbs/dpj-38605-1.html /*本程序 ...