4 Replies Latest reply on Aug 26, 2010 5:55 AM by John Lister

    AmbiguousResolutionException when extending a base class

    John Lister Newbie
      Hi, I'm getting the following except when loading my module under Glassfish v3.01 using the Jersey framework, although I'm using jersey this would appear to be a weld issue...


      org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [<<LIST OF CLASSES>>]

      Where the list is a list of Jersey resources which are themselves managed beans in order to allow me to inject other entities. The problem seems to be that all the beans listed extend a common base class (which isn't managed).

      Is it possible to avoid this error/warning and prevent the ambiguity with respect to the base class or should I redesign the structure of the beans?

      Thanks
        • 1. Re: AmbiguousResolutionException when extending a base class
          Nicklas Karlsson Master

          Show the hierarchy and what you're @Inject:ing

          • 2. Re: AmbiguousResolutionException when extending a base class
            John Lister Newbie
            Hi, thanks for your reply..

            The actual error is (I've split the class list up for clarity) The full exception trace is at the end
            org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [
            org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class Product,
            org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class Search,
            org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class Base,
            org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class Account,
            org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class Home]

            Whereby all the above extend Base and are defined as such:

            @Path("/product/")
            @ManagedBean
            public class Product extends Base {
            ...
            }

            and within the resource classes I do injection such as
                @Inject UserBean user;
                @Inject SiteBean siteBean;
                @EJB AccountBean accountBean;

            where by the first 2 are CDI beans (using @Named) and don't extend anything, whereas the latter is a standard stateless EJB again not extending any other class. Base is a simple POJO and doesn't have any injection. Finally I don't inject any of the above resources into anything else, I'm making them managed purely to allow me to inject additional beans.


            Thanks

            John

            full exception stack:
            org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class com.kickstone.pricegoblin.resources.Product, org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class com.kickstone.pricegoblin.resources.Search, org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class com.kickstone.pricegoblin.resources.Base, org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class com.kickstone.pricegoblin.resources.Account, org.jboss.weld.bean-/C:/src/java/PriceGoblin/PriceGoblinWeb/build/web/-ManagedBean-class com.kickstone.pricegoblin.resources.Home]
                    at org.jboss.weld.manager.BeanManagerImpl.resolve(BeanManagerImpl.java:1160)
                    at com.sun.jersey.server.impl.jcdi.JCDIComponentProviderFactory.getBean(JCDIComponentProviderFactory.java:244)
                    at com.sun.jersey.server.impl.jcdi.JCDIComponentProviderFactory.init(JCDIComponentProviderFactory.java:103)
                    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:654)
                    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:589)
                    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:403)
                    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:252)
                    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:550)
                    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:201)
                    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:307)
                    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:470)
                    at javax.servlet.GenericServlet.init(GenericServlet.java:242)
                    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1428)
                    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1060)
                    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:187)
                    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
                    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
                    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
                    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
                    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
                    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
                    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
                    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
                    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
                    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
                    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
                    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
                    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
                    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
                    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
                    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
                    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
                    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
                    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
                    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
                    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
                    at java.lang.Thread.run(Thread.java:619)


            • 3. Re: AmbiguousResolutionException when extending a base class
              Pete Muir Master

              This smells like a Weld/GlassFish integration problem - can you open a thread in the GlassFish forum and link it back to this thread for us. Siva will be able to investigate for you then.

              • 4. Re: AmbiguousResolutionException when extending a base class
                John Lister Newbie

                Hi, thanks for replying. Apparently this was (it has been fixed in a later revision that included with glassfish - which I'd not spotted) a jersey issue. I could originally only find a reference to a similar issue under Jersey that suggested it was a Weld problem, hence my post here.


                Cheers


                John