How do I register my custom Environment Post Processor in Spring Boot 2.0?

Solution 1:

There is no elegant way to solve this. You can make something like this :

@Component
public class CustomEnvironmentPostProcessor implements
        EnvironmentPostProcessor, ApplicationListener<ApplicationEvent> {

    private static final DeferredLog log = new DeferredLog();

    @Override
    public void postProcessEnvironment(
            ConfigurableEnvironment env, SpringApplication app) {
        log.error("This should be printed");
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        log.replayTo(CustomEnvironmentPostProcessor.class);
    }
}

Solution 2:

define spring.factories file

Environment Post Processor

org.springframework.boot.env.EnvironmentPostProcessor=\
class name with package