javax.naming.NameNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3911856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javax.naming.NameNotFoundException
提问by sjain
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
我正在运行一个使用 JBoss5 容器的 ejb 示例。我正在使用这里的示例
(第一部分)。
在示例中,我在 JBoss 中部署了 bean,在 Tomcat 中部署了一个应用程序(从 JBoss 访问 bean)。我在 tomcat 服务器的屏幕中收到错误
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?
( greetJndi 是 jboss.xml 文件中的 jndi 名称)在 JBoss 中是否有要部署的特定目录结构?
Thanks
谢谢
采纳答案by Pascal Thivent
I am getting the error (...) javax.naming.NameNotFoundException: greetJndi not bound
我收到错误 (...) 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 qualityof this tutorial (check the server logs). I'll come back on this.
这意味着没有任何内容绑定到 jndi name greetJndi
,很可能是由于本教程质量极低的部署问题(检查服务器日志)。我会回来的。
Is there any specific directory structure to deploy in JBoss?
在 JBoss 中是否有任何特定的目录结构要部署?
The internal structure of the ejb-jar
is supposed to be like this (using the poor naming conventions and the default packageas in the mentioned link):
的内部结构ejb-jar
应该是这样的(使用糟糕的命名约定和提到的链接中的默认包):
. ├── 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 theejb-jar.xml
(!) - a space is missing after
PUBLIC
in theejb-jar.xml
andjboss.xml
(!!) - the
jboss.xml
is incorrect, it should contain asession
element instead ofentity
(!!!)
- (!) 中有一个额外的字符 (
<enterprise-beans>]
<-- HEREejb-jar.xml
) - 一个空间后失踪
PUBLIC
的ejb-jar.xml
和jboss.xml
(!!) - 在
jboss.xml
不正确,它应该包含一个session
元素,而不是entity
(!)
Here is a "fixed" version of the ejb-jar.xml
:
这是 的“固定”版本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
:
其中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:
完成这些更改并重新打包 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'
That tutorial needs significant improvement; I'd advise from staying away from roseindia.net.
该教程需要显着改进;我建议远离roseindia.net。
回答by Piotr Kochański
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.
该错误意味着您正在尝试查找未附加到任何 EJB 组件的 JNDI 名称 - 具有该名称的组件不存在。
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:
就目录结构而言:您必须创建一个带有 EJB 组件的 JAR 文件。据我了解,您想使用 EJB 2.X 组件(至少链接示例表明),因此 JAR 文件的结构应该是:
/com/mypackage/MyEJB.class /com/mypackage/MyEJBInterface.class /com/mypackage/etc... etc... java classes /META-INF/ejb-jar.xml /META-INF/jboss.xml
/com/mypackage/MyEJB.class /com/mypackage/MyEJBInterface.class /com/mypackage/etc... 等等... java 类 /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.
JAR 文件或多或少是 ZIP 文件,文件扩展名从 ZIP 更改为 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
顺便提一句。如果您使用 JBoss 5,您可以使用 EJB 3.0,它更容易配置。最简单的组件是
@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.
不需要 ejb-jar.xml、jboss.xml,只需要带有 MyEJB 和 MyEJBInterface 编译类的 EJB JAR。
Now in your client code you need to lookup "MyComponentName".
现在,在您的客户端代码中,您需要查找“MyComponentName”。