11 Replies Latest reply on Feb 21, 2012 6:59 PM by stepanov

    CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called

    stepanov

      I'm implementing a simple CDI extension which is performing some actions after @Singleton EJB start. The stripped-down idea is like this:

      • I have an EJB which is marked with @Singleton and @Startup and has a @PostConstruct method.
      • In my Extension implementation I observe ProcessInjectionTarget event
      • If InjectionTarget satisfies to some criteria, I wrap it with my implementation of InjectionTarget which basically just delegates calls to the wrapped instance.
      • In the wrapping InjectionTarget I do some actions in postConstruct() method before delegating the call.

       

      What I expect to see is postConstruct() method called on my InjectionTarget wrapper after singleton start. However, it never happens (although the singleton EJB itself starts fine). Log shows the follwing calls sequence:

      • ProcessInjectionTarget observing method on my Extension class
      • getInjectionPoints() method on my wrapping InjectionTarget class (two times - got no idea why)
      • inject() on my wrapping InjectionTarget class
      • @PostConstruct method on the singleton EJB

      ... and that's it.

       

      Am I missing something or my assumption that InjectionTarget.postConstruct() method must be called after singleton startup is wrong?

       

      Attached is a project for reproducing this behavior. I'm testing it under JBoss 7.1.0.Beta1b. Any suggestions are appreciated.