6 Replies Latest reply on Jul 26, 2010 8:14 AM by Francois Swiegers

    Interceptors with InjectionTarget of Dependent scoped beans

    Francois Swiegers Newbie

      Good day

      I'm trying to use an interceptor on a dependent scoped bean that gets its dependencies injected via an InjectionTarget as per the Weld user guide section 16.4.

      The injection works fine, but I am not able to get an interceptor to work that I defined on my bean. The reason for this seems to be that the


      method does not return a proxied instance, but a direct reference to my bean. My understanding is that interceptors and decorators won't work unless Weld gives me back a proxy.

      If I inject the above mentioned bean directly using @Inject, then Weld does create a proxied instance and the interceptor works fine.     

      Is this a bug in Weld, or do I need to something special using the InjectionTarget to tell it to return a proxy instead of the concrete instance?

      A related question: is it possible to get CDI to wrap an existing instance into a proxy to enable interceptors and decorators to work? My problem is that I don't control the creation of my objects, but I want them to take advantage of CDI's interceptors and dependency injection capabilities. However, looking at InjectionTarget, it does not provide an inject method that returns a proxy.