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?

syntagma
  • 23,346
  • 16
  • 78
  • 134
jit
  • 452
  • 1
  • 7
  • 26

1 Answers1

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

Juan Rada
  • 3,513
  • 1
  • 26
  • 26