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

CICFlowMeter源码分析以及为满足需求而进行的修改

Ggplot2 color setting summary

二叉树第一部分

Handling method of Oracle data file header SCN inconsistency

Cicflowmeter source code analysis and modification to meet requirements

Arbre binaire partie 1

文献调研报告

生产者/消费者模型

How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
随机推荐
How to manage massive network infrastructure?
Summary of medical image open source datasets (II)
微信小程序学习之 实现列表渲染和条件渲染.
【Eureka 源码分析】
《MATLAB 神经网络43个案例分析》:第32章 小波神经网络的时间序列预测——短时交通流量预测
请问有国内靠谱低手续费的期货开户渠道吗?网上开户安全吗?
How to standardize data center infrastructure management process
How to solve multi-channel customer communication problems in independent stations? This cross-border e-commerce plug-in must be known!
SQL statistics of users logged in for N consecutive days
PTA monkey chooses King (Joseph Ring problem)
413-二叉树基础
port 22: Connection refused
Thinkphp5 clear the cache cache, temp cache and log cache under runtime
Producer / consumer model
20、 Processor scheduling (RR time slice rotation, mlfq multi-level feedback queue, CFS fully fair scheduler, priority reversal; multiprocessor scheduling)
生产者/消费者模型
Wechat applet learning to achieve list rendering and conditional rendering
Oracle数据文件头SCN不一致处理方法
Endgame P.O.O
100 GIS practical application cases (XIV) -arcgis attribute connection and using Excel