forked from coderbruis/JavaSourceCodeLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondInitializer.java
More file actions
30 lines (26 loc) · 1.08 KB
/
SecondInitializer.java
File metadata and controls
30 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.bruis.learnsb.initializer;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import java.util.HashMap;
import java.util.Map;
/**
* @author LuoHaiYang
*
* 模拟SpringBoot的系统初始化器的调用
*
*/
@Order(2)
public class SecondInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
ConfigurableEnvironment environment = configurableApplicationContext.getEnvironment();
Map<String, Object> map = new HashMap<>();
map.put("key", "value");
MapPropertySource mapPropertySource = new MapPropertySource("SecondInitializer", map);
environment.getPropertySources().addLast(mapPropertySource);
System.out.println("run SecondInitializer");
}
}