Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-763

CDI issue: Cannot locate the BeanManager for JavaEE 6

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 6.0.0, 5.0.11
    • 5.0.10, 6.0.0
    • General
    • JBoss AS 7.1

      According the stack trace "Caused by: javax.naming.NameNotFoundException: env/BeanManager", this JNDI resource name doesn't exist in Java EE Environment (in this case, JBoss AS 7.1).
      The API document of Java EE 6 indicated that the JNDI name of BeanManager is "java:comp/BeanManager": http://docs.oracle.com/javaee/6/api/javax/enterprise/inject/spi/BeanManager.html

      Stack trace
      type Exception report
      
      message
      
      description The server encountered an internal error () that prevented it from fulfilling this request.
      
      exception
      
      org.zkoss.xel.XelException: Cannot locate the BeanManager for JavaEE 6.
      	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      	org.zkoss.lang.Classes.newInstance(Classes.java:73)
      	org.zkoss.lang.Exceptions.wrap(Exceptions.java:206)
      	org.zkoss.xel.XelException$Aide.wrap(XelException.java:47)
      	org.zkoss.zkplus.cdi.CDIUtil.getBeanManager(CDIUtil.java:44)
      	org.zkoss.zkplus.cdi.DelegatingVariableResolver.<init>(DelegatingVariableResolver.java:39)
      	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      	java.lang.Class.newInstance0(Class.java:372)
      	java.lang.Class.newInstance(Class.java:325)
      	org.zkoss.zk.ui.metainfo.ArgumentInfo.newInstance(ArgumentInfo.java:64)
      	org.zkoss.zk.ui.metainfo.VariableResolverInfo.newVariableResolver(VariableResolverInfo.java:141)
      	org.zkoss.zk.ui.metainfo.VariableResolverInfo.newVariableResolver(VariableResolverInfo.java:111)
      	org.zkoss.zk.ui.metainfo.PageDefinition.initXelContext(PageDefinition.java:424)
      	org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:373)
      	org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:309)
      	org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:220)
      	org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:140)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
      	org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
      root cause
      
      javax.naming.NameNotFoundException: env/BeanManager -- service jboss.naming.context.java.module."cdi.example"."cdi.example".env.BeanManager
      	org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:92)
      	org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177)
      	org.jboss.as.naming.InitialContext.lookup(InitialContext.java:97)
      	org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213)
      	javax.naming.InitialContext.lookup(InitialContext.java:411)
      	org.zkoss.zkplus.cdi.CDIUtil.getBeanManager(CDIUtil.java:42)
      	org.zkoss.zkplus.cdi.DelegatingVariableResolver.<init>(DelegatingVariableResolver.java:39)
      	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      	java.lang.Class.newInstance0(Class.java:372)
      	java.lang.Class.newInstance(Class.java:325)
      	org.zkoss.zk.ui.metainfo.ArgumentInfo.newInstance(ArgumentInfo.java:64)
      	org.zkoss.zk.ui.metainfo.VariableResolverInfo.newVariableResolver(VariableResolverInfo.java:141)
      	org.zkoss.zk.ui.metainfo.VariableResolverInfo.newVariableResolver(VariableResolverInfo.java:111)
      	org.zkoss.zk.ui.metainfo.PageDefinition.initXelContext(PageDefinition.java:424)
      	org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:373)
      	org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:309)
      	org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:220)
      	org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:140)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
      	org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
      note The full stack trace of the root cause is available in the JBoss Web/7.0.7.Final logs.
      

      The code caused this issue is from CDIUtil in ZK plus.
      This might be a simple solution:

      CDIUtil.java
      package org.zkoss.zkplus.cdi;
      import javax.enterprise.inject.spi.BeanManager;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import org.zkoss.xel.XelException;
      public class CDIUtil
      {
      	private static BeanManager _manager;
      	public static BeanManager getBeanManager()
      	{
      		if(_manager != null)
      			return _manager;
      		try
      		{
      			final InitialContext initialContext = new InitialContext();
      			_manager = (BeanManager)initialContext.lookup("java:comp/env/BeanManager");
      		}
      		catch(NamingException e)
      		{
      			try
      			{
      				final InitialContext initialContext = new InitialContext();
      				_manager = (BeanManager)initialContext.lookup("java:comp/BeanManager");
      			}
      			catch(NamingException e1)
      			{
      				throw XelException.Aide.wrap(e1, "Cannot locate the BeanManager for JavaEE 6.");
      			}
      		}
      		return _manager;
      	}
      }
      

            jumperchen jumperchen
            paowang paowang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: