本文介绍了尝试通过JNDI查找BeanManager时为WELD-001300的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照焊接文档.

一切正常,除了通过JNDI查找BeanManager之外.查找其他JNDI条目恰如预期的那样工作.我收到错误消息(请注意,这不是javax.naming.NameNotFoundException)

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

我使用的代码:

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;

完整的测试代码可以在 https://github上找到.com/rmuller/java8-examples/tree/master/jetty-maven-cdi

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

推荐答案

这具有与我在Tomcat 7/8和Weld 2.2.6中遇到的问题类似的症状.就我而言,这与WELD中的错误有关,该错误已在2.2.7中修复.因此它不应该影响原始海报的设置.

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

这篇关于尝试通过JNDI查找BeanManager时为WELD-001300的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 22:11