Conditional @PostConstruct annotation
Asked Answered
A

1

7

I sometimes may not need to post-construct of a bean at startup according to values passed via JVM argument.

I tried @Conditional annotation but it only works on @Bean annotations.

Have you tried/needed such a thing before?

Anyways answered 4/10, 2017 at 8:35 Comment(0)
R
1

AFAIK Conditional can not be mix with postconstruct. So my suggetions

  1. Add two diferent beans one with postconstruct and one without as use @Conditional in beans declaration

  2. Add programatic code validatiing your application args like:

    import org.springframework.core.env.Environment;
    
    private final Environment env;
    
    public void execute() {
        if (env.getProperty("condition") == "condition") {
        }
    }
    
  3. Use aproximation in 1 but @Profile and pass active profile as parameter -Dspring.profiles.active=my_profile

Ruction answered 1/11, 2018 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.