1 Reply Latest reply on Sep 14, 2015 3:02 AM by mkouba

    Registering a Bean dynamiclly

    asafbennatan

      Hi,

      i came across this issue , i have a system that loads jars dynamically (on run-time),

      once a jar appears on a specified folder i load a class which implements a pre-defined interface using classLoader,

      i want to enable these jars to use injection services from the core.

      i have tried using InjectionTarget and all is fine taking account simple situations (injecting already known beans etc..)but looking at a bit more complex situation :

      Jar contains:

      A.java

      B.java

      and A has this field :

      @inject

      B b;

       

      obviously when injecting A with intectionTarget B is not registered (or even loaded) so InjectionTarget creation fails,

      is there any way loading a whole jar with all dependencies together ?

      looking at the docs i have seen the Extension interface (not sure if it even solves the issue )but the problem is that the implementing interface should be listed in some text file - thus preventing the core to be totally dynamic

      (obviously a crude option here is to write that file and issue a server restart somehow but i would like to avoid that)

       

       

      using wildfly 8.2 with built-in weld version

       

      Thanks.

        • 1. Re: Registering a Bean dynamiclly
          mkouba

          Hi,

          CDI is not designed this way - i.e. it does not support "dynamic registration" right now (version 1.2, Java EE 7). So it's not possible to register beans, observer and other CDI metadata at runtime. Maybe you could make use of OSGi and Pax CDI.