Spring boot 要打印在spring启动应用程序启动期间加载的属性吗
谁能解释一下下面的代码中发生了什么Spring boot 要打印在spring启动应用程序启动期间加载的属性吗,spring-boot,spring-boot-maven-plugin,spring-boot-admin,Spring Boot,Spring Boot Maven Plugin,Spring Boot Admin,谁能解释一下下面的代码中发生了什么 MapPropertySource有什么用途 除了MapPropertySource和applicationConfig,还有哪些其他选项 为什么我们要过滤foreach public void handleContextRefreshed(ContextRefreshedEvent事件){ printActiveProperties((ConfigurableEnvironment)event.getApplicationContext().getEnvir
public void handleContextRefreshed(ContextRefreshedEvent事件){
printActiveProperties((ConfigurableEnvironment)event.getApplicationContext().getEnvironment());
}
私有void printActiveProperties(ConfigurableEnvironment环境){
System.out.println(“**********************************************************************************************”);
List propertySources=new ArrayList();
env.getPropertySources().forEach(it->{
if(它是MapPropertySource的实例&&it.getName()包含(“applicationConfig”)){
添加((MapPropertySource)它);
}
});
propertySources.stream()
.map(propertySource->propertySource.getSource().keySet())
.flatMap(集合::流)
.distinct()
.已排序()
.forEach(键->{
试一试{
System.out.println(key+“=”+env.getProperty(key));
}捕获(例外e){
log.warn(“{}->{}”,key,e.getMessage());
}
});
System.out.println(“*******************************************************************************************************************************************”);
}```
你想解释一下你自己的代码吗?这不是我写的。代码存在于
public void handleContextRefreshed(ContextRefreshedEvent event) {
printActiveProperties((ConfigurableEnvironment) event.getApplicationContext().getEnvironment());
}
private void printActiveProperties(ConfigurableEnvironment env) {
System.out.println("************************* ACTIVE APP PROPERTIES ******************************");
List<MapPropertySource> propertySources = new ArrayList<>();
env.getPropertySources().forEach(it -> {
if (it instanceof MapPropertySource && it.getName().contains("applicationConfig")) {
propertySources.add((MapPropertySource) it);
}
});
propertySources.stream()
.map(propertySource -> propertySource.getSource().keySet())
.flatMap(Collection::stream)
.distinct()
.sorted()
.forEach(key -> {
try {
System.out.println(key + "=" + env.getProperty(key));
} catch (Exception e) {
log.warn("{} -> {}", key, e.getMessage());
}
});
System.out.println("******************************************************************************");
}```