JBOSS 5.1.0 Beta中的JNDI名称绑定

时间:2009-06-22 08:52:54

标签: jboss java-ee ejb-3.0 jndi

我正在关注我从The Server Site网站下载的MasteringEJB4thEdition书。

有一个简单的HelloBean示例,它与GlassFish V3应用服务器完美配合。部署在JBOSS上的相同示例因JNDI名称查找而失败。

如果我们不提供任何规则,是否有规则如何决定JBOSS中的JNDI查找名称?我在google搜索时发现它是“ear-file-name / Bean-class-name / remote”但它对我不起作用。

这是豆


   1. package com.hardik.stateless;  
   2. import javax.ejb.Stateless;  
   3. import javax.ejb.Remote  
   4.   
   5.   
   6.   
   7.   
   8. @Stateless  
   9. @Remote(Hello.class)  
  10. public class HelloBean implements Hello {  
  11.   
  12.     public String hello() {  
  13.         System.out.println("hello()");  
  14.         return "Hello, World!";  
  15.     }  
  16.   
  17. }  

以下是我正在使用的客户:


   1. package com.hardik.stateless;  
   2.   
   3. import javax.naming.Context;  
   4. import javax.naming.InitialContext;  
   5.   
   6.   
   7. /** 
   8.  * This is an example of client code which invokes  
   9.  * methods on a simple, remote stateless session bean 
  10.  * @author hardik 
  11.  * 
  12.  */  
  13. public class HelloClient {  
  14.       
  15.     public static void main(String[] args) throws Exception {  
  16.           
  17.         Context ctx = new InitialContext();  
  18.         // works for Glassfish  
  19.         //Hello hello = (Hello) ctx.lookup("com.hardik.stateless.Hello");  
  20.         // doesn't  work for JBOSS  
  21.         Hello hello = (Hello) ctx.lookup("hello-bean/HelloBean/remote");  
  22.           
  23.         System.out.println(hello.hello());  
  24.     }  
  25.   
  26. }  

这是我在执行客户端时遇到的错误


# $ wsrunclient.sh -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=jnp://localhost:1099  -cp "lib/hello-bean.jar:dist/hello-client.jar:/home/hardik/apps/jboss/client/*"  com.hardik.stateless.HelloClient  
# log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).  
# log4j:WARN Please initialize the log4j system properly.  
# Exception in thread "main" javax.naming.NameNotFoundException: hello-bean not bound  
#         at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)  
#         at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)  
#         at org.jnp.server.NamingServer.getObject(NamingServer.java:785)  
#         at org.jnp.server.NamingServer.lookup(NamingServer.java:396)  
#         at sun.reflect.GeneratedMethodAccessor260.invoke(Unknown Source)  
#         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
#         at java.lang.reflect.Method.invoke(Method.java:597)  
#         at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)  
#         at sun.rmi.transport.Transport$1.run(Transport.java:159)  
#         at java.security.AccessController.doPrivileged(Native Method)  
#         at sun.rmi.transport.Transport.serviceCall(Transport.java:155)  
#         at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)  
#         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)  
#         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)  
#         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
#         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
#         at java.lang.Thread.run(Thread.java:619)  
#         at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)  
#         at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)  
#         at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)  
#         at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)  
#         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:722)  
#         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:682)  
#         at javax.naming.InitialContext.lookup(InitialContext.java:392)  
#         at com.hardik.stateless.HelloClient.main(Unknown Source)

4 个答案:

答案 0 :(得分:2)

我在搜索后修复了问题。我不得不将命名空间信息添加到我的ejb-jar.xml文件中。

我改变了它 从:

<ejb-jar> 
    <enterprise-beans>
    </enterprise-beans> 
</ejb-jar>

为:

   1. <?xml version="1.0" encoding="UTF-8"?>  
   2. <ejb-jar version="3.0"   
   3.     xmlns="http://java.sun.com/xml/ns/javaee"  
   4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
   5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
   6.     http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">  
   7. </ejb-jar>  

我在这里找到答案: http://www.jboss.org/index.html?module=bb&op=viewtopic&t=157022

答案 1 :(得分:1)

我认为您必须在Properties中添加Client/log4j.properties

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p
%c{1}:%L - %m%n
log4j.rootLogger=INFO, stdout

答案 2 :(得分:0)

我不确定JBoss 5,但在JBoss 4下,JMX控制台有一个名为JNDIView的MBean,它具有将整个JNDI树转储到控制台的操作。如果在JBoss 5中仍然存在,那么你应该能够在那里找到你的EJB。

答案 3 :(得分:0)

我用jmx控制台检查了jndi视图,bean只在内部注册,而不是在Global JNDI中注册。我在部署时看到以下消息......


12:15:44,016 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=hello-bean.ear,jar=hello-bean.jar,name=HelloBean,service=EJB3) to KernelDeployment of: hello-bean.jar
12:15:44,048 INFO  [SessionSpecContainer] Starting jboss.j2ee:ear=hello-bean.ear,jar=hello-bean.jar,name=HelloBean,service=EJB3
12:15:44,048 INFO  [EJBContainer] STARTED EJB: com.hardik.mejb.HelloBean ejbName: HelloBean
12:15:44,048 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:


12:15:44,078 WARN  [WebServiceDeployerEJB] Ingore ejb deployment with null classname: org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData@bebe0782{HelloBean}