javax.naming.NameNotFoundException

发布于 2024-09-27 05:25:09 字数 357 浏览 3 评论 0原文

我正在使用 JBoss5 容器运行 ejb 示例。我正在使用一个例子 从这里(第一部分)
在示例中,我在 JBoss 中部署了 bean,并在 Tomcat 中部署了一个应用程序(以从 JBoss 访问 bean)。我在 tomcat 服务器的屏幕上收到错误
javax.naming.NameNotFoundException:greetJndi未绑定

(greetJndi是jboss.xml文件中的jndi名称) JBoss 中部署有什么特定的目录结构吗?

谢谢

I am running an example of ejb using JBoss5 Container. I am using an example
from here(Part one).

In the example I deployed bean in JBoss and an application in Tomcat(to acces the bean from JBoss). I am getting the error in the screen of tomcat server

javax.naming.NameNotFoundException: greetJndi not bound

( greetJndi is the jndi-name in jboss.xml file )
Is there any specific directory structure to deploy in JBoss?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尴尬癌患者 2024-10-04 05:25:09

我收到错误 (...) javax.naming.NameNotFoundException:greetJndi 未绑定

这意味着没有任何内容绑定到 jndi 名称 greetJndi,很可能是由于给定 的部署问题本教程的质量极低(检查服务器日志)。我会回来讨论这个。

在 JBoss 中部署有什么特定的目录结构吗?

ejb-jar 的内部结构应该是这样的(使用糟糕的命名约定和默认包,如提到的链接中所示):

.
├── greetBean.java
├── greetHome.java
├── greetRemote.java
└── META-INF
    ├── ejb-jar.xml
    └── jboss.xml

但是正如已经提到的,本教程充满了错误:

  • ejb-jar.xml 中有一个额外的字符 (] <-- HERE) (!)
  • ejb-jar.xmljboss.xml 中的 PUBLIC 之后缺少一个空格 (!!)
  • jboss.xml< /code> 不正确,它应该包含 session 元素而不是 entity (!!!)

这是 ejb-jar 的“固定”版本。 xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>greetBean</ejb-name>
      <home>greetHome</home>
      <remote>greetRemote</remote>
      <ejb-class>greetBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>
</ejb-jar>

以及 jboss.xml

<?xml version="1.0"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
<jboss>
  <enterprise-beans>
    <session>
      <ejb-name>greetBean</ejb-name>
      <jndi-name>greetJndi</jndi-name>
    </session>
  </enterprise-beans>
</jboss>

在进行这些更改并重新打包 ejb-jar 后,我能够成功部署它:

21:48:06,512 INFO  [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@5060868{vfszip:/home/pascal/opt/jboss-5.1.0.GA/server/default/deploy/greet.jar/}
21:48:06,534 INFO  [EjbDeployer] installing bean: ejb/#greetBean,uid19981448
21:48:06,534 INFO  [EjbDeployer]   with dependencies:
21:48:06,534 INFO  [EjbDeployer]   and supplies:
21:48:06,534 INFO  [EjbDeployer]    jndi:greetJndi
21:48:06,624 INFO  [EjbModule] Deploying greetBean
21:48:06,661 WARN  [EjbModule] EJB configured to bypass security. Please verify if this is intended. Bean=greetBean Deployment=vfszip:/home/pascal/opt/jboss-5.1.0.GA/server/default/deploy/greet.jar/
21:48:06,805 INFO  [ProxyFactory] Bound EJB Home 'greetBean' to jndi 'greetJndi'

该教程需要重大改进;我建议远离roseindia.net。

I am getting the error (...) javax.naming.NameNotFoundException: greetJndi not bound

This means that nothing is bound to the jndi name greetJndi, very likely because of a deployment problem given the incredibly low quality of this tutorial (check the server logs). I'll come back on this.

Is there any specific directory structure to deploy in JBoss?

The internal structure of the ejb-jar is supposed to be like this (using the poor naming conventions and the default package as in the mentioned link):

.
├── greetBean.java
├── greetHome.java
├── greetRemote.java
└── META-INF
    ├── ejb-jar.xml
    └── jboss.xml

But as already mentioned, this tutorial is full of mistakes:

  • there is an extra character (<enterprise-beans>] <-- HERE) in the ejb-jar.xml (!)
  • a space is missing after PUBLIC in the ejb-jar.xml and jboss.xml (!!)
  • the jboss.xml is incorrect, it should contain a session element instead of entity (!!!)

Here is a "fixed" version of the ejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>greetBean</ejb-name>
      <home>greetHome</home>
      <remote>greetRemote</remote>
      <ejb-class>greetBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>
</ejb-jar>

And of the jboss.xml:

<?xml version="1.0"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
<jboss>
  <enterprise-beans>
    <session>
      <ejb-name>greetBean</ejb-name>
      <jndi-name>greetJndi</jndi-name>
    </session>
  </enterprise-beans>
</jboss>

After doing these changes and repackaging the ejb-jar, I was able to successfully deploy it:

21:48:06,512 INFO  [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@5060868{vfszip:/home/pascal/opt/jboss-5.1.0.GA/server/default/deploy/greet.jar/}
21:48:06,534 INFO  [EjbDeployer] installing bean: ejb/#greetBean,uid19981448
21:48:06,534 INFO  [EjbDeployer]   with dependencies:
21:48:06,534 INFO  [EjbDeployer]   and supplies:
21:48:06,534 INFO  [EjbDeployer]    jndi:greetJndi
21:48:06,624 INFO  [EjbModule] Deploying greetBean
21:48:06,661 WARN  [EjbModule] EJB configured to bypass security. Please verify if this is intended. Bean=greetBean Deployment=vfszip:/home/pascal/opt/jboss-5.1.0.GA/server/default/deploy/greet.jar/
21:48:06,805 INFO  [ProxyFactory] Bound EJB Home 'greetBean' to jndi 'greetJndi'

That tutorial needs significant improvement; I'd advise from staying away from roseindia.net.

燕归巢 2024-10-04 05:25:09

该错误意味着您正在尝试查找未附加到任何 EJB 组件的 JNDI 名称 - 具有该名称的组件不存在。

就目录结构而言:您必须使用 EJB 组件创建一个 JAR 文件。据我了解,您想要使用 EJB 2.X 组件(至少链接的示例表明了这一点),因此 JAR 文件的结构应该是:

/com/mypackage/MyEJB.class
/com/mypackage/MyEJBInterface.class
/com/mypackage/etc...等等...java 类
/META-INF/ejb-jar.xml
/META-INF/jboss.xml

JAR 文件或多或少是 ZIP 文件,文件扩展名从 ZIP 更改为 JAR。

顺便提一句。如果您使用 JBoss 5,则可以使用 EJB 3.0,它更容易配置。最简单的组件是

@Stateless(mappedName="MyComponentName")
@Remote(MyEJBInterface.class)
public class MyEJB implements MyEJBInterface{
   public void bussinesMethod(){

   }
}

不需要 ejb-jar.xml,需要 jboss.xml,只需带有 MyEJB 和 MyEJBInterface 编译类的 EJB JAR。

现在,在您的客户端代码中,您需要查找“MyComponentName”。

The error means that your are trying to look up JNDI name, that is not attached to any EJB component - the component with that name does not exist.

As far as dir structure is concerned: you have to create a JAR file with EJB components. As I understand you want to play with EJB 2.X components (at least the linked example suggests that) so the structure of the JAR file should be:

/com/mypackage/MyEJB.class
/com/mypackage/MyEJBInterface.class
/com/mypackage/etc... etc... java classes
/META-INF/ejb-jar.xml
/META-INF/jboss.xml

The JAR file is more or less ZIP file with file extension changed from ZIP to JAR.

BTW. If you use JBoss 5, you can work with EJB 3.0, which are much more easier to configure. The simplest component is

@Stateless(mappedName="MyComponentName")
@Remote(MyEJBInterface.class)
public class MyEJB implements MyEJBInterface{
   public void bussinesMethod(){

   }
}

No ejb-jar.xml, jboss.xml is needed, just EJB JAR with MyEJB and MyEJBInterface compiled classes.

Now in your client code you need to lookup "MyComponentName".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文