Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

spring-boot

I followed the exact steps in this documentation.

I have the following entries in my META-INF/spring.factories

org.springframework.boot.env.EnvironmentPostProcessor=com.mygroup.myapp.CustomEnvironmentPostProcessor

My post processor:

public class CustomEnvironmentPostProcessor
        implements EnvironmentPostProcessor, Ordered {
..
}

I don't see anything in the logs as if it didn't get registered or not existing.

I unzipped the JAR and I can see META-INF/spring.factories. I can also see BOOT-INF/classes directly from the root.

What am I missing here?

like image 677
supertonsky Avatar asked Oct 25 '25 22:10

supertonsky


2 Answers

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);
    }
}
like image 145
Eugen Avatar answered Oct 28 '25 03:10

Eugen


define spring.factories file

Environment Post Processor

org.springframework.boot.env.EnvironmentPostProcessor=\
class name with package
like image 38
Shokoladova Avatar answered Oct 28 '25 04:10

Shokoladova



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!