6 Replies Latest reply on Mar 4, 2014 8:33 AM by Ali Cheaito

    Veto a Session bean

    Ali Cheaito Newbie

      I'm on Weld 1.1.10 (jBoss EAP 6). We have a jar containing the following EJB:


      public class EjbWorker implements WorkerInterface {
          public void doWork() {
            //do stuff


      It seems that WELD is automatically registering EjbWorker as the @Default implementation of WorkerInterface. This is not desired for our set up, and we are looking for a way to stop it, preferably without modifying the EJB.

      We attempted to veto the bean registration in a CDI Portable Extension, however the ProcessAnnotatedType event was never fired for EjbWorker.


      Is there any other way to stop the session bean from becoming the default implementation in this case? It is worth noting that the jar where the EJB lives does not contain a beans.xml file.

        • 1. Re: Veto a Session bean
          Martin Kouba Master

          Hi Ali,

          that's odd. In CDI 1.0 the session bean that is not in a bean archive should never be discovered. Actually it seems it is not - as ProcessAnnotatedType is not fired. What does the injection point look like? How did you find out that  EjbWorker is registered?

          • 2. Re: Re: Veto a Session bean
            Ali Cheaito Newbie

            I left out some details that seemed irrelevant. We have a Portable Extension (ServiceBeanCreator) that registers beans from non-discoverable archives by means of AfterBeanDiscovery event.addBean(). One such bean is RegularWorker, which also implements WorkerInterface. The extension runs fine and the beans register, however when the bean is requested from BeanManager like so:


            Bean<WorkeInterface> bean = (Bean<WorkeInterface>) beanManager.resolve(beanManager.getBeans(WorkerInterface.class, new AnnotationLiteral<Default>(){}));
            WorkerInterface instance = beanManager.getContext(bean.getScope()).get(bean, beanManager.createCreationalContext(bean));


            an exception is thrown:

            org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [com.company.cdi.ext.ServiceBeanCreator$1@37b6b182,
            Session bean [class com.company.worker.impl.ejb.EjbWorker with qualifiers [@Any @Default]; local interfaces are [EjbWorker]]


            Also, in the extension, I listen to ProcessSessionBean and ProcessManagedBean and both are called for EjbWorker.

            • 3. Re: Re: Veto a Session bean
              Martin Kouba Master

              The container should definitely not fire ProcessManagedBean for any session bean. Could you provide a simplified version of your archive, so that we're able to reproduce your issue locally?

              • 4. Re: Re: Re: Veto a Session bean
                Ali Cheaito Newbie

                Simplified version attached as requested.


                The TestJar Eclipse project has the interface, impl, and Ejb.

                TestWeb has the injection target as well as the portable extension. Once Deployed, clicking the doWork button on the index.xhtml will throw the ambiguous resolution exception.

                • 5. Re: Re: Re: Veto a Session bean
                  Martin Kouba Master

                  Would it be possible to attach the final WAR? I don't use the required Eclipse plugins.

                  • 6. Re: Re: Re: Re: Veto a Session bean
                    Ali Cheaito Newbie

                    Attached. This was compiled with Java 7.


                    EDIT: Just realized I left out the source files from the WAR export. Here's a version with the source.