| package org.eclipse.openk.contactbasedata.service; |
| |
| import lombok.extern.log4j.Log4j2; |
| import org.springframework.boot.env.OriginTrackedMapPropertySource; |
| import org.springframework.context.event.ContextRefreshedEvent; |
| import org.springframework.context.event.EventListener; |
| import org.springframework.core.env.AbstractEnvironment; |
| import org.springframework.core.env.Environment; |
| import org.springframework.core.env.MutablePropertySources; |
| import org.springframework.stereotype.Component; |
| |
| import java.util.Arrays; |
| import java.util.stream.StreamSupport; |
| |
| @Log4j2 |
| @Component |
| public class InitPropertyLogger { |
| |
| @EventListener |
| public void handleContextRefresh(ContextRefreshedEvent event) { |
| final Environment environment = event.getApplicationContext().getEnvironment(); |
| log.info("\n"); |
| log.info("============== Configuration =============="); |
| log.info("Active profile: {}", Arrays.toString(environment.getActiveProfiles())); |
| final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); |
| StreamSupport.stream(sources.spliterator(), false) |
| .filter(ps -> ps instanceof OriginTrackedMapPropertySource) |
| .map(ps -> ((OriginTrackedMapPropertySource) ps).getPropertyNames()) |
| .flatMap(Arrays::stream) |
| .distinct() |
| .forEach(prop -> log.info("{}: {}", prop, environment.getProperty(prop))); |
| log.info("===========================================\n"); |
| } |
| } |