Model

Avatar

Avatar

AdobeID24

Avatar

AdobeID24

AdobeID24

24-07-2019

  • 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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Himanshu_Singhal

MVP

Avatar

Himanshu_Singhal

MVP

Himanshu_Singhal
MVP

29-07-2019

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()

}

Answers (2)

Answers (2)

Avatar

Avatar

Himanshu_Singhal

MVP

Avatar

Himanshu_Singhal

MVP

Himanshu_Singhal
MVP

24-07-2019

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

Avatar

AdobeID24

Avatar

AdobeID24

AdobeID24

29-07-2019

Can we use two post construct method ?