当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢
Why is LNX of e equal to X
canvas 绘制图片
Grpc local test joint debugging tool bloomrpc
20、 Processor scheduling (RR time slice rotation, mlfq multi-level feedback queue, CFS fully fair scheduler, priority reversal; multiprocessor scheduling)
Use of vim
英伟达这篇CVPR 2022 Oral火了!2D图像秒变逼真3D物体!虚拟爵士乐队来了!
How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
Wechat applet learning to achieve list rendering and conditional rendering
ssh远程免密登录
Impdp leading schema message ora-31625 exception handling
随机推荐
How do novices choose the grade of investment and financial products?
SSH Remote Password free login
PTA monkey chooses King (Joseph Ring problem)
Threejs MMD model loading + contour loading + animation loading + Audio loading + camera animation loading +ammojs loading gltf model loading +gltf reflection adjustment
针对《VPP实现策略路由》的修正
port 22: Connection refused
canvas 绘制图片
Mise en œuvre du rendu de liste et du rendu conditionnel pour l'apprentissage des applets Wechat.
How to standardize data center infrastructure management process
GIS实战应用案例100篇(十四)-ArcGIS属性连接和使用Excel的问题
【自定义Endpoint 及实现原理】
如何解决独立站多渠道客户沟通难题?这款跨境电商插件一定要知道!
[custom endpoint and implementation principle]
PRCT-1400 : 未能执行 getcrshome解决方法
IDEA 无法保存设置 源根 D:XXXX在模块XXX中重复
Why is LNX of e equal to X
微信小程序學習之 實現列錶渲染和條件渲染.
Regular matching mailbox
ssh远程免密登录
Algorithm - the K row with the weakest combat power in the matrix (kotlin)