【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的代码按照原来的加载顺序进行 ...
随机推荐
- AtCoder Regular Contest 080 (ARC080) E - Young Maids 线段树 堆
原文链接http://www.cnblogs.com/zhouzhendong/p/8934377.html 题目传送门 - ARC080 E - Young Maids 题意 给定一个长度为$n$的 ...
- IDEA创建javaSE项目
- day14,函数的使用方法:生成器表达式,生成器函数
生成器表达式: #列表推导式 # y = [1,2,3,4,5,6,7,8] # x = [1,4,9,16,25,36,49,64] # x = [] # for i in y: # x.appen ...
- 大数据及Hadoop的概述
一.大数据存储和计算的各种框架即工具 1.存储:HDFS:分布式文件系统 Hbase:分布式数据库系统 Kafka:分布式消息缓存系统 2.计算:Mapreduce:离线计算框架 stor ...
- Java 之 Web前端(五)
1.过滤器 a.定义:是一个中间组件,用于拦截源数据和目的数据之间的消息,并过滤二者之间传递的数据 b.步骤: ①建class继承Filter实现抽象方法 public class EncodingF ...
- NN:神经网络实现识别手写的1~9的10个数字—Jason niu
import numpy as np from sklearn.datasets import load_digits from sklearn.metrics import confusion_ma ...
- 四、Python导入自己写的包报错:没有该包如何解决
场景:当你运行文件时,提示没有你想要导入的这个包,这是只需在你运行文件的开头添加俩行代码: import sys sys.path.apprnd('../') 原理:请看图解 另外解释下sys.pat ...
- Django 学习第三天——模板变量及模板过滤器
一.模板路径的查找: 查找顺序:(现在哪找到就用那个) 首先在主目录的 setting.py 文件里的 TEMPLATES 中的 DIRS 里找: 其次如果 DIRS 中的 APP_DIRS : 'T ...
- 【C#】Convert.ToInt32、(int)和int.Parse三者的区别
前者适合将object类类型转换成int类型 (int)适合简单数据类型之间的转换: int.Parse适合将string类类型转换成int类型.
- 课堂练习&课下作业----用户场景分析
典型用户1 ·小明---一名普通大学生生 名字 小明 性别.年龄 男,19岁 职业 大学生 收入 无 知识层次和能力 石家庄铁道大学学生,善于交际. 生活/工作情况 成绩优异,各方面技能突出 动机,目 ...