Expand my Community achievements bar.

SOLVED

Model

Avatar

Level 7
  • can we have multiple  two @PostConstruct method in one  model class  ?

      and my both method having suppose 15 -15 injcetion . As we know post construct will get invoked only when all injcetion will get resolved . ? so means how it will             work all 30 injection ll get resolved and then post constriuct method will be called ?

  • defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL(this will make ALL injection optional)

         suppose i have to mek some 15 injection optiponal and 15 required . Then i HAVE TO PUT @REQUIRED with each injection ..there is not any gloabl                   way to do that

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Why do you need to use 2 PostConstruct method. If you wanna split the logic, you can write in 2 months and both methods you can call inside @PostConstruct method.

E.g.

method1()

method2()

@PostConstruct

method init() {

     method1()

     method2()

}

View solution in original post

3 Replies

Avatar

Community Advisor

Hi,

defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL - It will make all the injectors optional so if any injectors won't be able to get the value, it won't any error.

If you don't specifically define OPTIONAL and then in that case, you'll have to mark injectors as @Optional otherwise if it couldn't any value, then it'll throw error.

And, yes, @PostConstruct will be resolved once all the injectors are injected.

There's no other global way to handle the scenario. You'll have to use either one of approach.

Avatar

Level 7

Can we use two post construct method ?

Avatar

Correct answer by
Community Advisor

Why do you need to use 2 PostConstruct method. If you wanna split the logic, you can write in 2 months and both methods you can call inside @PostConstruct method.

E.g.

method1()

method2()

@PostConstruct

method init() {

     method1()

     method2()

}