2 Replies Latest reply on Mar 3, 2014 7:39 AM by mkouba

    Is really a @Decorator an injectable managed bean?

    lucasvc

      I'm new using the @Decorator annotation, and it fits perfect. But I'm facing problemas injecting a bean annotated.

      As CDI-1.1 docs says:

      • It is a concrete class, or is annotated @Decorator.

      So I supposed that my @Decorator bean could be injected as other bean, but it is not working in a Tomcat 6 with weld-servlet-2.1.2.Final. I'm trying to inject the bean in a javax.servlet.Filter, without even using it. While other beans are correctly injected, when I add the injection of the bean I get:

      org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type DecoratedFoo with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private com.foo.FooFilter.foo at com.foo.FooFilter.foo(FooFilter.java:0)

              at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:368)

              ...

       

      These are the three classes (interface, real implementation and decorated implementation)

      public interface FooI {
          String getS();
      }
      

       

      public class ImplementationFoo implements FooI {
          public String getS() {
              return "a";
          }
      }
      

       

      @Decorator
      public class DecoratedFoo implements FooI {
          @Inject
          @Delegate
          private FooI delegate;
      
          public String getS() {
              return delegate.getS() + "b";
          }
      }
      

       

      And the filter only is:

      public class FooFilter implements Filter {
          @Inject
          private DecoratedFoo foo;
          [rest of filter methods]
      }
      

       

      I'm doing something wrong? Is a weld bug? Is a doc bug?

        • 1. Re: Is really a @Decorator an injectable managed bean?
          mkouba

          Hi Lucas,

          the sentence you are referencing (3.1.1 Which Java classes are managed beans?) implies that the decorator class may be abstract. I.e. the decorator is not required to implement every method of every decorated type. However a decorator is always a dependent object of the object it decorates. So it's not possible to inject into any other bean. Actually it does not make much sense. The purpose of decorators (similar to interceptors) is to intercept business method invocations and do some business-logic-aware operations. See also 5.1.4 Inter-module injection: "A bean is available for injection in a certain module if the bean is not an interceptor or decorator..."

          • 2. Re: Is really a @Decorator an injectable managed bean?
            mkouba

            And the short version of the answer: No, it is not.