当前位置:网站首页>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);
}
}

边栏推荐
- 文献调研报告
- js单例模式
- MYSQL数据高级
- 【Eureka 源码分析】
- Five heart matchmaker
- Arbre binaire partie 1
- 【Eureka注册中心】
- NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!
- SQL statistics of users logged in for N consecutive days
- Baidu AI template for knowledge understanding
猜你喜欢

PTA monkey chooses King (Joseph Ring problem)

如何让社交媒体成为跨境电商驱动力?这款独立站工具不能错过!

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

Ora-28000 error after upgrading Oracle 12C to 19C

Indexeddb local storage, homepage optimization

How to solve multi-channel customer communication problems in independent stations? This cross-border e-commerce plug-in must be known!

Practical analysis: implementation principle of APP scanning code landing (app+ detailed logic on the web side) with source code

Literature Research Report

js单例模式

413-二叉树基础
随机推荐
MYSQL数据高级
Symbol. Iterator iterator
英伟达这篇CVPR 2022 Oral火了!2D图像秒变逼真3D物体!虚拟爵士乐队来了!
ssh远程免密登录
el-table点击添加行样式
Is there a reliable and low commission futures account opening channel in China? Is it safe to open an account online?
Endgame P.O.O
CICFlowMeter源码分析以及为满足需求而进行的修改
Baidu AI template for knowledge understanding
indexedDB本地存储,首页优化
Oracle viewing data file header SCN information
Tnsnames Ora file configuration
如何管理海量的网络基础设施?
LeetCode: 377. Combined sum IV
414-二叉树的递归遍历
Five heart matchmaker
十大证券公司哪个佣金最低,最安全可靠?有知道的吗
新手怎么选择投资理财产品的等级?
请问有国内靠谱低手续费的期货开户渠道吗?网上开户安全吗?
JCIM|药物发现中基于AI的蛋白质结构预测:影响和挑战