当前位置:网站首页>ApplicationContextInitializer的三种使用方法
ApplicationContextInitializer的三种使用方法
2022-06-24 08:05:00 【cx7】
ApplicationContextInitializer是在Springboot启动过程(refresh方法前)调用,ApplicationContextInitializer实现主要有3中方式:
先创建一个类实现ApplicationContextInitializer这个接口,实现对应的方法。
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
public class TestContextInitializer implements ApplicationContextInitializer {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
System.out.println("我加载了!!!!!!!!!!!");
}
}
1、使用spring.factories方式
在resource下面新建/META-INF/spring.factories文件。
2、application.properties添加配置方式:
对于这种方式是通过DelegatingApplicationContextInitializer这个初始化类中的initialize方法获取到application.properties中context.initializer.classes对应的类并执行对应的initialize方法。只需要将实现了ApplicationContextInitializer的类添加到application.properties即可。如下:
3、在启动类修改启动方式。
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);
}
}

边栏推荐
- 软件系统依赖关系分析
- 【ES6闯关】Promise堪比原生的自定义封装(万字)
- The list of open source summer winners has been publicized, and the field of basic software has become a hot application this year
- Niuke network realizes simple calculator function
- 活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热报名中
- 2022.6.13-6.19 AI行业周刊(第102期):职业发展
- Netrca: an effective network fault cause localization
- Transplantation of xuantie e906 -- fanwai 0: Construction of xuantie c906 simulation environment
- Data middle office: overview of data governance
- Solution: the word of jmeter5.5 on the win11 lower interface is very small
猜你喜欢

"I can't understand Sudoku, so I choose to play Sudoku."

2022.6.13-6.19 AI行业周刊(第102期):职业发展
![[ES6 breakthrough] promise is comparable to native custom encapsulation (10000 words)](/img/b3/b156d75c7b4f03580c449f8499cd74.png)
[ES6 breakthrough] promise is comparable to native custom encapsulation (10000 words)

Xiaobai needs to learn MySQL - incremental statistical SQL

CF566E-Restoring Map【bitset】

4274. suffix expression

支持向量机(SVC,NuSVC,LinearSVC)

Ordinary people have no education background. Can they earn more than 10000 yuan a month by Self-taught programming?

uniapp 开发多端项目如何配置环境变量以及区分环境打包

Linux (centos7.9) installation and deployment of MySQL Cluster 7.6
随机推荐
【ES6闯关】Promise堪比原生的自定义封装(万字)
Redis实现全局唯一ID
"I can't understand Sudoku, so I choose to play Sudoku."
[noi Simulation Competition] send (tree DP)
Spark - the number of leftouterjoin results is inconsistent with that of the left table
【LeetCode】541. Reverse string II
2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
Huawei Router: IPSec Technology
Solution: the word of jmeter5.5 on the win11 lower interface is very small
Data middle office: middle office practice and summary
1844. replace all numbers with characters
When to use RDD and dataframe/dataset
On the routing tree of gin
【gdb调试工具】| 如何在多线程、多进程以及正在运行的程序下调试
陆奇:我现在最看好这四大技术趋势
Target detection series fast r-cnn
The printed object is [object object]. Solution
金仓KFS replicator安装(Oracle-KES)
Kaformer personal notes
Data middle office: middle office architecture and overview