【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的代码按照原来的加载顺序进行 ...
随机推荐
- Codeforces 316E3 线段树 + 斐波那切数列 (看题解)
最关键的一点就是 f[ 0 ] * a[ 0 ] + f[ 1 ] * a[ 1 ] + ... + f[ n - 1] * a[ n - 1] f[ 1 ] * a[ 0 ] + f[ 2 ] * ...
- Codeforces 1016G Appropriate Team 数论 FWT
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1016G.html 题目传送门 - CF1016G 题意 给定 $n,x,y$ ,以及一个含有 $n$ 个元 ...
- js下拉列表
js清除下拉列表所选默认值 $("#lineId").val(“”); js清除下拉列表所有选项 $("#type").html(""); ...
- 学习Spring必须了解的基础知识——回调机制
上面这张图如果能看得懂就能理解什么是回调机制: A对象在调用a()方法时会调用B对象的b()方法,b()方法必须能调用A对象的callback()方法. 谁白了:a()方法有B对象b()方法的引用,b ...
- Tomcat启动分析(转自:http://docs.huihoo.com/apache/tomcat/heavyz/01-startup.html)
Tomcat启动分析 1 - Tomcat Server的组成部分 1.1 - Server A Server element represents the entire Catalina servl ...
- 大数据小白系列——MR(1)
一部编程发展史就是一部程序员偷懒史,MapReduce(下称MR)同样是程序员们用来偷懒的工具. 来了一份大数据,我们写了一个程序准备分析它,需要怎么做? 老式的处理方法不行,数据量太大时,所需的时间 ...
- Oracle Loop
1. LOOP - END LOOP - EXIT declare v_rlt ):; begin v_rlt:; loop dbms_output.put_line('loop'||v_rlt); ...
- [C程序设计基础]一些常用的系统函数
- js发送邮件 不会调用客户端。
方式三:使用node中nodemail 首先需要安装node的环境,然后安装nodemailer: npm install nodemailer --save npm install nodemail ...
- 1014 Uniform Generator ACM
http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目的英文实在是太多了 ,搞不懂. 最后才知道是用公式seed(x+1) = [seed(x) + STE ...