JNDI查找仅返回“javax.naming.NameNotFoundException”

时间:2011-11-23 11:57:10

标签: gwt jboss jndi

我正在尝试使用JNDI命名来实现ejb调用。

设定:

  • JBoss-6.1.0.Final
  • 耳部署:
    • gwt.war
    • ejb.jar

我的问题是,虽然JNDIView向我展示了现有的ejb,但我无法联系到它。

在我的RemoteServiceServlet中,我尝试访问ejb,ejb部署在同一个ear-package内的ejb.jar中。

我已经尝试了几次调用,因为我不确定正确的jndi代码。

try 
{
    productLocal = (ProductLocal) context.lookup("ProductHome/local");
} 
catch (NamingException e) 
{
    System.err.println(e.getMessage());
    e.printStackTrace();
}

也尝试过:

productLocal = (ProductLocal) context.lookup("ProductLocal");
productLocal = (ProductLocal) context.lookup("sung_app_kylintv/ProductHome/local");

无状态ejb 的分配如下:

@Stateless
@Local(ProductLocal.class)
@Remote(ProductRemote.class)
@LocalBinding(jndiBinding="ProductLocal")
@RemoteBinding(jndiBinding="ProductRemote")
public class ProductHome extends HomeBase<ProductEntity> implements SessionBean, Serializable, ProductLocal

上下文启动

Properties p = new Properties();
p.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
p.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
p.put("java.naming.provider.url","jnp://localhost:1099");

context = new InitialContext(p);

我的 JNDIView

  +- sung_app_kylintv (class: org.jnp.interfaces.NamingContext)
  |   +- CategoryHome (class: org.jnp.interfaces.NamingContext)
  |   |   +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryLocal)
  |   |   +- local-sung.app.kylintv.ejbclient.product.CategoryLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryLocal)
  |   |   +- remote-sung.app.kylintv.ejbclient.product.CategoryRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryRemote)
  |   |   +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryRemote)
  |   +- ProductHome (class: org.jnp.interfaces.NamingContext)
  |   |   +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductLocal)
  |   |   +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductRemote)
  |   |   +- remote-sung.app.kylintv.ejbclient.product.ProductRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductRemote)
  |   |   +- local-sung.app.kylintv.ejbclient.product.ProductLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductLocal)
  |   +- CustomerHome (class: org.jnp.interfaces.NamingContext)
  |   |   +- local-sung.common.behavior.FindAllBehaviour (class: Proxy for: sung.common.behavior.FindAllBehaviour)
  |   |   +- local (class: Proxy for: sung.common.behavior.FindAllBehaviour)
  |   +- Option (class: org.jnp.interfaces.NamingContext)
  |   |   +- local-sung.app.kylintv.ejbclient.product.OptionLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionLocal)
  |   |   +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionLocal)
  |   |   +- remote-sung.app.kylintv.ejbclient.product.OptionRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionRemote)
  |   |   +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionRemote)
  |   +- DurationHome (class: org.jnp.interfaces.NamingContext)
  |   |   +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationLocal)
  |   |   +- local-sung.app.kylintv.ejbclient.product.DurationLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationLocal)
  |   |   +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationRemote)
  |   |   +- remote-sung.app.kylintv.ejbclient.product.DurationRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationRemote)
  |   +- VariantHome (class: org.jnp.interfaces.NamingContext)
  |   |   +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantLocal)
  |   |   +- local-sung.app.kylintv.ejbclient.product.VariantLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantLocal)
  |   |   +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantRemote)
  |   |   +- remote-sung.app.kylintv.ejbclient.product.VariantRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantRemote)
  |   +- VelocityBean (class: org.jnp.interfaces.NamingContext)
  |   |   +- local (class: Proxy for: sung.app.kylintv.ejb.velocity.Velocity)
  |   |   +- local-sung.app.kylintv.ejb.velocity.Velocity (class: Proxy for: sung.app.kylintv.ejb.velocity.Velocity)
  |   +- CustomerAddressHome (class: org.jnp.interfaces.NamingContext)
  |   |   +- local-sung.common.behavior.FindAllBehaviour (class: Proxy for: sung.common.behavior.FindAllBehaviour)
  |   |   +- local (class: Proxy for: sung.common.behavior.FindAllBehaviour)
  |   +- OrderEntityHome (class: org.jnp.interfaces.NamingContext)
  |   |   +- no-interface (class: sung.app.kylintv.ejbclient.order.OrderEntityHome_$$_javassist_50)

在这样的情况下,是否有任何要求jndi正常工作?

1 个答案:

答案 0 :(得分:0)

使用

productLocal = (ProductLocal) context.lookup("sung_app_kylintv/ProductHome/local")

返回了稍有不同的错误消息:

2011-11-24 12:37:07,893 INFO  [STDOUT] (http-0.0.0.0-8080-2) productLocal called successfully.
2011-11-24 12:37:07,893 INFO  [STDOUT] (http-0.0.0.0-8080-2) productLocal calling createTestEntry().
2011-11-24 12:37:07,950 ERROR [STDERR] (http-0.0.0.0-8080-2) org.jboss.injection.manager.spi.InjectionException: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: sung not bound]

在我的一位同事看了之后发现了错误:我在该类ProductHome中使用 @EJB尝试了一次注入,使用了mappedName =“sung /...”。 mappedName不正确,甚至根本不需要,在ejb项目中,连接已经存在并且正常工作。希望,这也可以帮助其他人。

<强>解决方案: 我必须通过删除ejb-call上的mappedName-Attribute来修复我的ProductHome。之后,可以实现类,并调用函数。