[英]javax.naming.NameNotFoundException
I am running an example of ejb using JBoss5 Container. 我正在使用JBoss5 Container运行ejb的示例。 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). 在示例中,我在JBoss中部署了bean,在Tomcat中部署了一个应用程序(从JBoss访问bean)。 I am getting the error in the screen of tomcat server
我在tomcat服务器的屏幕上收到错误
javax.naming.NameNotFoundException: greetJndi not bound
javax.naming.NameNotFoundException:greetJndi未绑定
( greetJndi is the jndi-name in jboss.xml file ) Is there any specific directory structure to deploy in JBoss? (greetJndi是jboss.xml文件中的jndi-name)是否有任何特定的目录结构要在JBoss中部署?
Thanks 谢谢
I am getting the error (...) javax.naming.NameNotFoundException: greetJndi not bound
我收到错误(...)javax.naming.NameNotFoundException:greetJndi没有绑定
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). 这意味着没有任何内容绑定到jndi名称
greetJndi
,很可能是因为部署问题,因为本教程质量非常低 (检查服务器日志)。 I'll come back on this. 我会回来的。
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 package as 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: 但正如已经提到的,本教程充满了错误:
<enterprise-beans>]
<-- HERE) in the ejb-jar.xml
(!) ejb-jar.xml
(!)中有一个额外的字符( <enterprise-beans>]
< - HERE) PUBLIC
in the ejb-jar.xml
and jboss.xml
(!!) ejb-jar.xml
和jboss.xml
(!!)中的PUBLIC
之后缺少空格 jboss.xml
is incorrect, it should contain a session
element instead of entity
(!!!) 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。
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. 就dir结构而言:您必须使用EJB组件创建JAR文件。 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 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 ... 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. JAR文件或多或少的ZIP文件,文件扩展名从ZIP更改为JAR。
BTW. BTW。 If you use JBoss 5, you can work with EJB 3.0, which are much more easier to configure.
如果您使用JBoss 5,您可以使用EJB 3.0,它更容易配置。 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. 不需要ejb-jar.xml,jboss.xml,只需要带有MyEJB和MyEJBInterface编译类的EJB JAR。
Now in your client code you need to lookup "MyComponentName". 现在在您的客户端代码中,您需要查找“MyComponentName”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.