12 Replies Latest reply on Dec 12, 2016 3:45 AM by Martin Kouba

    Decorator problems with programmatically added Bean

    Laird Nelson Apprentice

      I have an extension that adds a Bean (which reports Foo, an interface, among its types) during AfterBeanDiscovery.

       

      I have a decorator, an abstract class implementing Foo, annotated with @Decorator and @Priority(javax.interceptor.Interceptor.Priority.APPLICATION), with a constructor annotated with @Inject, with a parameter in that constructor annotated with @Delegate.  In other words, I'm Doing It Right™.  I have no beans.xml.

       

      I am working with Weld 3.0.0 Alpha 17, so CDI 2.0 EDR2.

       

      I add the decorator class to the SeContainerInitializer using its addDecorators(Class<?>...) method.  (I did not add my Foo implementation to the bean classes, because the Bean representing Foo (and FooImpl) is added by my extension.)

       

      The decorator is not picked up.  I get the following error at initialize() time:

       

      org.jboss.weld.exceptions.DeploymentException: WELD-001419: Enabled decorator class com.foobar.FooDecorator is not the bean class of at least one decorator bean (detected decorator beans:

        - org.jboss.weld.environment.se.threading.RunnableDecorator)

        at org.jboss.weld.bootstrap.Validator.validateEnabledDecoratorClasses(Validator.java:667)

        at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:470)

        at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:461)

        at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)

        at org.jboss.weld.environment.se.Weld.initialize(Weld.java:790)

       

      Although I find the wording of this error message confusing, I suspect this has to do with the fact that AfterBeanDiscovery::addBean adds my Foo, but the decorator class can't be associated with that bean for some reason.

       

      So: how can I get my decorator to work here?  Must I programmatically add a javax.inject.spi.Decorator representing it as well?