2 Replies Latest reply on May 24, 2011 8:21 AM by jharting

    Injecting pre-CDI class

    bhiles

      OK. I've been searching for an answer on this question for a few days and either I'm not seeing the forest for the trees, or this cannot be done.


      I have the need to inject classes from a library (jar) that was developed before CDI was created. I need to be able to inject a class from this library into a CDI capable application. The problem is I can't crack the library and inject the beans.xml file. Is there any way to do this? It is being done now using Spring DI and I'm trying to find a way to do it via CDI.


      I've seen posts like this one that only seem to confirm that this cannot be done.


      If it cannot, I think it is a big oversight. I'd love to be able to modify a beans.xml file in the parent application to allow this to happen.


      Thanks.

        • 1. Re: Injecting pre-CDI class
          th.janssen

          As described in http://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html_single/#bean-definition the beans.xml is required in each archive which contains beans that shall be injected somewhere else.

          • 2. Re: Injecting pre-CDI class
            jharting

            The spec says:



            Note that this second bean exists—and may be enabled and available for injection—even if the first bean is disabled, as defined by Section 5.1.2, “Enabled and disabled beans”, or if the bean class is deployed outside of a bean archive, as defined in Section 12.1, “Bean archives”, and is therefore not discovered during the bean discovery process defined in Chapter 12, Packaging and deployment. The container discovers @New qualified beans by inspecting injection points of other enabled beans.

            Therefore, you can inject any bean from a no-beans-xml archive using @New.