当前位置:网站首页>Three ways to use applicationcontextinitializer
Three ways to use applicationcontextinitializer
2022-06-24 09:58:00 【cx7】
ApplicationContextInitializer Is in Springboot The boot process (refresh Before the method ) call ,ApplicationContextInitializer The realization mainly includes 3 In the way :
First create a class implementation ApplicationContextInitializer This interface , Implement the corresponding method .
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
public class TestContextInitializer implements ApplicationContextInitializer {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
System.out.println(" I loaded it !!!!!!!!!!!");
}
}
1、 Use spring.factories The way
stay resource Next new /META-INF/spring.factories file .
2、application.properties Add configuration mode :
For this way is through DelegatingApplicationContextInitializer In this initialization class initialize Method to get application.properties in context.initializer.classes The corresponding class and execute the corresponding initialize Method . Just make it happen ApplicationContextInitializer Added to application.properties that will do . as follows :
3、 Modify the startup method in the startup class .
package com.llq.testdemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContextInitializer;
@SpringBootApplication
public class TestDemoApplication {
public static void main(String[] args) {
// SpringApplication.run(TestDemoApplication.class, args);
SpringApplication application = new SpringApplication(TestDemoApplication.class);
application.addInitializers(new TestContextInitializer());
application.run(args);
}
}

边栏推荐
- latex公式及表格识别
- el-table表格的拖拽 sortablejs
- grpc本地测试联调工具BloomRPC
- Open Oracle server under Linux to allow remote connection
- 【Eureka注册中心】
- How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
- PHP file lock
- R ellipse random point generation and drawing
- Endgame P.O.O
- 如何规范化数据中心基础设施管理流程
猜你喜欢

411-栈和队列(20. 有效的括号、1047. 删除字符串中的所有相邻重复项、150. 逆波兰表达式求值、239. 滑动窗口最大值、347. 前 K 个高频元素)

有关二叉树 的基本操作

Prct-1400: failed to execute getcrshome resolution

How to manage massive network infrastructure?

2021-08-17

IDEA 无法保存设置 源根 D:XXXX在模块XXX中重复

indexedDB本地存储,首页优化

英伟达这篇CVPR 2022 Oral火了!2D图像秒变逼真3D物体!虚拟爵士乐队来了!

Canvas draw picture

In depth study paper reading target detection (VII) Chinese English Bilingual Edition: yolov4 optimal speed and accuracy of object detection
随机推荐
顶刊TPAMI 2022!基于不同数据模态的行为识别:最新综述
Codeforces Round #392 (Div. 2) D. Ability To Convert
How to improve the efficiency of network infrastructure troubleshooting and bid farewell to data blackouts?
How to standardize data center infrastructure management process
Symbol.iterator 迭代器
Geogebra instance clock
[Eureka source code analysis]
js单例模式
英伟达这篇CVPR 2022 Oral火了!2D图像秒变逼真3D物体!虚拟爵士乐队来了!
impdp导schema报ORA-31625异常处理
如何提高网络基础设施排障效率,告别数据断档?
R 椭圆随机点产生并画图
Impdp leading schema message ora-31625 exception handling
PostgreSQL DBA快速入门-通过源码编译安装
十大证券公司哪个佣金最低,最安全可靠?有知道的吗
如何让社交媒体成为跨境电商驱动力?这款独立站工具不能错过!
R ellipse random point generation and drawing
Dragging El table sortablejs
ByteDance Interviewer: talk about the principle of audio and video synchronization. Can audio and video be absolutely synchronized?
413-二叉树基础