Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » The calling class org.jboss.resteasy.cdi.CdiInjectorFactory is placed in multiple bean archives
The calling class org.jboss.resteasy.cdi.CdiInjectorFactory is placed in multiple bean archives [message #1800349] Tue, 25 December 2018 09:31
Eclipse UserFriend
As Jetty is supported by the Eclipse foundation, I post my question on this forum.
I try to deploy and run a Java-angular-maven-multi module application INSIDE ECLIPSE on Jetty 9.4.8 .

Here is my web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <display-name>Tourism Applicationwith Angular</display-name>
    <description>
        This is a simple web application with a source code organization
        based on the recommendations of the Application Developer's Guide.
    </description>
    <display-name>Archetype Created Web Application</display-name>


    <listener>
    <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
  </listener>

   <listener>
    <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
  </listener>



      <resource-env-ref>
        <description>Object factory for the CDI Bean Manager</description>
        <resource-env-ref-name>BeanManager</resource-env-ref-name>
        <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
      </resource-env-ref>    

    <servlet>
        <servlet-name>Resteasy</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>webservice.TourismWebService</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>Resteasy</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>


    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

</web-app>


I expose the CDI bean manager through JNDI by creating jetty-env.xml under WEB-INF (http://www.agorava.org/news/2012/07/10/Starting-a-CDI-webapp-from-Maven-with-Weld-servlet-and-jetty-plugin/)
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
    <Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
        <New id="BeanManager" class="org.eclipse.jetty.plus.jndi.Resource">
            <Arg>
                <Ref id="webAppCtx"/>
            </Arg>
            <Arg>BeanManager</Arg>
            <Arg>
                <New class="javax.naming.Reference">
                    <Arg>javax.enterprise.inject.spi.BeanManager</Arg>
                    <Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
                    <Arg/>
                </New>
            </Arg>
        </New>
    </Configure>


To allow Jetty to load the server Classes, I create the file jetty-web.xml under WEB-INF (http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading)
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
    <Configure class="org.eclipse.jetty.webapp.WebAppContext">
       <Call name="prependServerClass">
          <Arg>-org.eclipse.jetty.servlet.listener.IntrospectorCleaner</Arg>
       </Call>   
       <Call name="prependServerClass">
          <Arg>-org.eclipse.jetty.servlet.listener.ELContextCleaner</Arg>
       </Call>    
       <Call name="prependServerClass">
          <Arg>-org.eclipse.jetty.util.Decorator</Arg>
       </Call>
       <Call name="prependServerClass">
          <Arg>-org.eclipse.jetty.util.DecoratedObjectFactory</Arg>
       </Call>
       <Call name="prependServerClass">
          <Arg>-org.eclipse.jetty.server.handler.ContextHandler.</Arg>
       </Call>
       <Call name="prependServerClass">
          <Arg>-org.eclipse.jetty.server.handler.ContextHandler</Arg>
       </Call>
       <Call name="prependServerClass">
          <Arg>-org.eclipse.jetty.servlet.ServletContextHandler</Arg>
       </Call>
    </Configure>


And when I run jetty to deploy my war, I have the following error. I searched deeply on the web, but found no solution
2018-11-21 20:41:16.229:INFO:oejs.session:main: No SessionScavenger set, using defaults
    2018-11-21 20:41:16.234:INFO:oejs.session:main: Scavenging every 660000ms
    20:41:16.328 [main] INFO org.jboss.weld.environment.servletWeldServlet - WELD-ENV-001006: org.jboss.weld.environment.servlet.EnhancedListener used to initialize Weld
    20:41:16.410 [main] DEBUG org.jboss.resteasy.cdi.i18n - RESTEASY010540: Doing a lookup for BeanManager in java:comp/BeanManager
    20:41:16.417 [main] DEBUG org.jboss.resteasy.cdi.i18n - RESTEASY010610: Unable to obtain BeanManager from java:comp/BeanManager
    20:41:16.417 [main] DEBUG org.jboss.resteasy.cdi.i18n - RESTEASY010540: Doing a lookup for BeanManager in java:app/BeanManager
    20:41:16.417 [main] DEBUG org.jboss.resteasy.cdi.i18n - RESTEASY010610: Unable to obtain BeanManager from java:app/BeanManager
    20:41:16.421 [main] DEBUG org.jboss.resteasy.cdi.i18n - RESTEASY010550: Error occurred trying to look up via CDI util.
    org.jboss.weld.exceptions.IllegalStateException: WELD-001327: Unable to identify the correct BeanManager. The calling class org.jboss.resteasy.cdi.CdiInjectorFactory is placed in multiple bean archives
        at org.jboss.weld.SimpleCDI.ambiguousBeanManager(SimpleCDI.java:95)
        at org.jboss.weld.SimpleCDI$ClassNameToBeanManager.findBeanManager(SimpleCDI.java:68)
        at org.jboss.weld.SimpleCDI$ClassNameToBeanManager.apply(SimpleCDI.java:46)
        at org.jboss.weld.SimpleCDI$ClassNameToBeanManager.apply(SimpleCDI.java:39)
        at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache$1.apply(ReentrantMapBackedComputingCache.java:55)
        at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache$1.apply(ReentrantMapBackedComputingCache.java:51)
        at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getValue(ReentrantMapBackedComputingCache.java:64)
        at org.jboss.weld.SimpleCDI.getBeanManager(SimpleCDI.java:104)
        at org.jboss.weld.SimpleCDI.getBeanManager(SimpleCDI.java:37)
        at org.jboss.resteasy.cdi.CdiInjectorFactory.lookupBeanManagerCDIUtil(CdiInjectorFactory.java:232)
        at org.jboss.resteasy.cdi.CdiInjectorFactory.lookupBeanManager(CdiInjectorFactory.java:152)
        at org.jboss.resteasy.cdi.CdiInjectorFactory.<init>(CdiInjectorFactory.java:44)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:148)
        at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28)
        at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:890)
        at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:532)
        at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:853)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:344)
        at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1515)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1477)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
        at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:133)
        at org.eclipse.jetty.server.Server.start(Server.java:418)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:107)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
        at org.eclipse.jetty.server.Server.doStart(Server.java:385)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at runjettyrun.Bootstrap.main(Bootstrap.java:89)
    20:41:16.423 [main] DEBUG org.jboss.resteasy.cdi.i18n - RESTEASY010565: Found BeanManager in ServletContext
    20:41:16.423 [main] DEBUG org.jboss.resteasy.cdi.i18n - RESTEASY010565: Found BeanManager in ServletContext


I posted this question on stackoverflow and had this answer :
Quote:



This is likely a configuration issue only.

This is the code that's triggering your error ...

https://github.com/weld/core/blob/6c2b09fac4e694a20877f017424acd6c4b3e3439/impl/src/main/java/org/jboss/weld/SimpleCDI.java#L50-L71

When CDI initializes it sees multiple Bean Managers.

Put a breakpoint in the for loop in that code so you can debug and see where it's pulling those Bean Managers from.



So I debugged it putting a breakpoint
index.php/fa/34565/0/

and here are three debug windows print screen
index.php/fa/34566/0/
index.php/fa/34567/0/
index.php/fa/34568/0/

Do you understand the signification of the code and if so could you explain me where is the error ?

It seems that the deployment takes into account twice the dependencies and there is a conflict between ones included in WEB-INF/lib and the dependencies coming from local maven repository (../.m2/repository/...)

Here is the configuration of Jetty on Eclipse
index.php/fa/34569/0/
  • Attachment: image5.png
    (Size: 151.32KB, Downloaded 498 times)
  • Attachment: image6.png
    (Size: 181.85KB, Downloaded 562 times)
  • Attachment: image7.png
    (Size: 198.25KB, Downloaded 520 times)
  • Attachment: image8.png
    (Size: 128.05KB, Downloaded 757 times)
  • Attachment: image9.png
    (Size: 137.14KB, Downloaded 553 times)

[Updated on: Wed, 26 December 2018 12:56] by Moderator

Previous Topic:[JDT API] Searching for particular method calls
Next Topic:deploy and run jetty OUTSIDE ECLIPSE for a war which consist of an angular-Java application
Goto Forum:
  


Current Time: Tue Jun 17 14:13:23 EDT 2025

Powered by FUDForum. Page generated in 0.03307 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top