EJB远程查找因javax.naming.NameNotFoundException而失败

时间:2013-02-24 21:07:14

标签: ejb-3.0 jboss7.x

我正在测试JBOSS 7.1.1服务器中的EJB Client。 EJB的服务端代码也在同一个VM上。它在运行时抛出“java.lang.ClassNotFoundException:com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote”错误。设置客户端似乎一切正常,但我无法弄清楚问题是什么。请让我知道我在哪里做错了。

服务器端代码

@Stateless(name = "WhiteBoardService")
@Local(IWhiteBoardService.class)
@Remote(IWhiteBoardServiceRemote.class)
public class WhiteBoardService implements IWhiteBoardService {

    private WhiteBoardPersistenceImpl whiteBoardPersistenceImpl = WhiteBoardPersistenceImpl
            .getInstance();
    private CoursePersistenceImpl coursePersistenceImpl = CoursePersistenceImpl
            .getInstance();

    @Override
    public LongKeyValue[] getWhiteBoardContent(long courseSessionGuid, UserSession userSession) {
        // returns the attachment Guid and the Attachment Title
        return whiteBoardPersistenceImpl.getAttachmentForWhiteBoard(courseSessionGuid, userSession) ;
    }......

本地接口

@Local
public interface IWhiteBoardService {

    public WhiteBoardSessionVO openWhiteBoard(long courseSessionGuid, UserSession userSession);
    public WhiteBoardSessionVO joinWhiteBoard(long courseSessionGuid,UserSession userSession);
    public LongKeyValue[] getWhiteBoardContent(long courseSessionGuid, UserSession userSession);
}

远程接口

public interface IWhiteBoardServiceRemote extends IWhiteBoardService{


}

EJB已经部署

20:42:32,278 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named WhiteBoardService in deployment unit subdeployment "emyed-ejb-1.0.jar" of deployment "emyed-ear.ear" are as follows:

    java:global/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    java:app/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    java:module/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    java:jboss/exported/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    java:global/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardService
    java:app/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardService
    java:module/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardService

客户等级

public class WhiteboardService {

    public static void main(String[] args){

        Context context=null;
           try
             {
                    Properties props = new Properties();
                    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                    props.put(Context.PROVIDER_URL, "remote://localhost:4447");
                    props.put(Context.SECURITY_PRINCIPAL, "ejbremote");
                    props.put(Context.SECURITY_CREDENTIALS, "remote4u");
                    context = new InitialContext(props);
                System.out.println("\n\tGot initial Context: "+context);
             }
           catch (Exception e)
             {
                    e.printStackTrace();
              }

             // Lookup Format will be
             // <app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>

           IWhiteBoardServiceRemote whiteboardService = null;
        try {
            Object obj = context.lookup("java:jboss/exported/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote");
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
             System.out.println("\n\t (\"MiddlewareMagic\") = "+ whiteboardService.getWhiteBoardContent(1, null));

    }

控制台日志

02:13:45,303  INFO xnio:63 - XNIO Version 3.0.3.GA
02:13:45,355  INFO nio:55 - XNIO NIO Implementation Version 3.0.3.GA
02:13:45,469  INFO remoting:70 - JBoss Remoting version 3.2.3.GA

    Got initial Context: javax.naming.InitialContext@5a92668c
javax.naming.NameNotFoundException: jboss/exported/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote -- service jboss.naming.context.java.jboss.exported.jboss.exported.emyed-ear."emyed-ejb-1.0"."WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote"
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
    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:662)
Exception in thread "main" java.lang.NoClassDefFoundError: com/zreflect/emyed/ejb/interfaces/IWhiteBoardServiceRemote
    at com.zreflect.emyed.whiteboard.service.WhiteboardService.main(WhiteboardService.java:47)
Caused by: java.lang.ClassNotFoundException: com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 1 more

2 个答案:

答案 0 :(得分:4)

您是否尝试过便携式JNDI名称:

java:global/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote

而不是

java:jboss/exported/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote

答案 1 :(得分:2)

您的堆栈跟踪表明客户端会抛出异常。这可能是因为您在客户端的类路径中没有com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote类定义。

您可能需要咨询Class loading in AS7。我将不得不看看您如何打包您的应用以进一步提供帮助。