5 Replies Latest reply on Apr 14, 2014 11:22 AM by Tomas Remes

    WELD-000047: Specializing bean must extend another bean

    Geoffrey Ragot Newbie

      Hello,

       

      i have a problem with weld.

      See my beans :

       

      @ObjectMapperDef(src=IDevice.class, dst=IDeviceSimpleDTO.class)

      @Singleton

      @Startup

      public class DeviceSimpleDTOMapper extends OrikaObjectMapper implements IObjectMapper {

           ....

      }

       

      @Alternative

      @Specializes

      public class DeviceSimpleDTOMapperExtended extends DeviceSimpleDTOMapper implements IObjectMapper {

           ........

      }


      These two beans are in two differents ejb modules.

      Here my beans.xml of the module containing the alternative bean :

      <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"

             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"

             bean-discovery-mode="all">

            

         <alternatives>

            <class>com.bhm.tools.pastille.webresource.mapping.output.DeviceSimpleDTOMapperExtended</class>

         </alternatives>

      </beans>

       

      So at the deployment, i get :

      Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000047: Specializing bean must extend another bean:  Managed Bean [class com.omwave.tools.pastille.webresource.mapping.output.DeviceSimpleDTOMapperExtended] with qualifiers [@Any @Default]

       

      I've found on google that some of old version of weld was break, but no recent pb with this.

       

      Any idea?

        • 1. Re: WELD-000047: Specializing bean must extend another bean
          Tomas Remes Expert

          Hi Geoffrey!

          It looks like the exception is correct in this case. From point of CDI spec view DeviceSimpleDTOMapper is session bean and DeviceSimpleDTOMapperExtended is not. I think it's not possible to specialize session bean with managed bean. CDI spec states:

           

          3.2.4. Specializing a session bean

          If a bean class of a session bean X is annotated @Specializes, then the bean class of X must

          directly extend the bean class of another session bean Y. Then X directly specializes Y, as defined

          in Section 4.3, “Specialization”.

          If the bean class of X does not directly extend the bean class of another session bean, the

          container automatically detects the problem and treats it as a definition error.

          1 of 1 people found this helpful
          • 2. Re: WELD-000047: Specializing bean must extend another bean
            Geoffrey Ragot Newbie

            Thanks for your reply.

             

            It's better. I've added annotation @Singleton on the specialized bean, and it seems that weld accept the specialization.

             

            However, i reach another error :

            org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type IObjectMapper with qualifiers @ObjectMapperDef

              at injection point [BackedAnnotatedField] @Inject @ObjectMapperDef private com.bhm.cgw.omconnect.mapping.output.device.PastilleDetailsDTOCustomizer.simpleDtoMapper

              at com.bhm.cgw.omconnect.mapping.output.device.PastilleDetailsDTOCustomizer.simpleDtoMapper(PastilleDetailsDTOCustomizer.java:0)

             

            It's related to the specialized beans. Weld give me some beans which match by type (but none by qualifier) which doesn't contains specialized beans or specializing beans.

            • 3. Re: WELD-000047: Specializing bean must extend another bean
              Tomas Remes Expert

              How does the interface IObjectMapper look like? I guess qualifiers are inherited in this case.

              • 4. Re: WELD-000047: Specializing bean must extend another bean
                Geoffrey Ragot Newbie

                Here the IObjectMapper interface :

                public interface IObjectMapper  {

                  public Object fromBean(Object ob, Class<?> dstClass) throws ObjectMapperException;

                  public Object fromBean(Object ob, Class<?> dstClass, Map<Object, Object> properties) throws ObjectMapperException;

                 

                  // This method allow to specify the src class from which the mapping have to be searched

                  public Object fromBean(Object ob, Class<?> dstClass, Class<?> srcClass) throws ObjectMapperException;

                  public Object fromBean(Object ob, Class<?> dstClass, Class<?> srcClass, Map<Object, Object> properties) throws ObjectMapperException;

                }

                 

                Here the ObjectMapperDef qualifier annotation :

                @Target({ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})

                @Retention(RetentionPolicy.RUNTIME)

                @Qualifier

                public @interface ObjectMapperDef {

                  public Class<?> src();

                  public Class<?> dst();

                }

                 

                Here a more complete trace of the error :

                org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type IObjectMapper with qualifiers @ObjectMapperDef

                  at injection point [BackedAnnotatedField] @Inject @ObjectMapperDef private com.bhm.cgw.omconnect.mapping.output.device.PastilleDetailsDTOCustomizer.simpleDtoMapper

                  at com.bhm.cgw.omconnect.mapping.output.device.PastilleDetailsDTOCustomizer.simpleDtoMapper(PastilleDetailsDTOCustomizer.java:0)

                WELD-001475: The following beans match by type, but none have matching qualifiers:

                  - Session bean [class com.bhm.tools.pastille.resource.mapping.CommandFacadeToAdapterMapper with qualifiers [@ObjectMapperDef @Any]; local interfaces are [IObjectMapper],

                  - Session bean [class com.bhm.cgw.omconnect.mapping.output.CommandListDTOMapper with qualifiers [@ObjectMapperDef @Any]; local interfaces are [IObjectMapper],

                  - Session bean [class com.bhm.cgw.omconnect.mapping.output.CommandDTOMapper with qualifiers [@ObjectMapperDef @Any]; local interfaces are [IObjectMapper],

                  - Session bean [class com.bhm.tools.pastille.webresource.mapping.output.RootDTOMapper with qualifiers [@ObjectMapperDef @Any]; local interfaces are [IObjectMapper],

                  - Session bean [class com.bhm.cgw.omconnect.mapping.output.DeviceListDTOMapper with qualifiers [@ObjectMapperDef @Any]; local interfaces are [IObjectMapper],

                  - Session bean [class com.bhm.tools.pastille.resource.mapping.CommandDefinitionToFacadeMapper with qualifiers [@ObjectMapperDef @Any]; local interfaces are [IObjectMapper]

                 

                The list give me all beans which implement IObjectMapper exception specializing and specialized beans.

                • 5. Re: WELD-000047: Specializing bean must extend another bean
                  Tomas Remes Expert

                  Well  the class com.bhm.cgw.omconnect.mapping.output.device.PastilleDetailsDTOCustomizer looks like quite different story. How does the injection point exactly looks like? ...and how does the class looks? I would guess members values (src, dst) for @ObjectMapperDef do not match....but that's just my guess.