WELD-001300 when trying to lookup BeanManager by JNDI

别来无恙 提交于 2019-12-22 17:52:01

问题


I configured Jetty 9.2.5 + Weld 2.2.7 (currently the latest versions) as described by the Weld documentation.

Everything works fine, except the lookup of the BeanManager by JNDI. Lookup of other JNDI entries just work as expected. I got the error (note this is not a javax.naming.NameNotFoundException)

javax.naming.NamingException: WELD-001300: Unable to locate BeanManager

The code I use:

BeanManager beanManager = null;
try {
    final Context ctx = new InitialContext();
    try {
        // JNDI name defined by spec
        beanManager = (BeanManager) ctx.lookup("java:comp/BeanManager");
    } catch (NameNotFoundException nf1) {
        try {
            // JNDI name used by Tomcat and Jetty
            beanManager = (BeanManager) ctx.lookup("java:comp/env/BeanManager");
        } catch (NameNotFoundException nf2) {
        }
    }
} catch (NamingException ex) {
    System.err.println(ex);
}
return beanManager;

Complete test code can be found at https://github.com/rmuller/java8-examples/tree/master/jetty-maven-cdi


回答1:


This has similar symptoms to a problem I ran into with Tomcat 7/8 and Weld 2.2.6. In my case, it was related to a bug in WELD, which was fixed in 2.2.7. So it shouldn't have been affecting the original poster's setup.

https://issues.jboss.org/browse/WELD-1776



来源:https://stackoverflow.com/questions/27666681/weld-001300-when-trying-to-lookup-beanmanager-by-jndi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!