簡體   English   中英

EJB遠程方法訪問

[英]EJB remote method access

我正在嘗試EJB 3示例進行遠程方法訪問。 一個簡單的示例,其中我正在編寫代碼並將其放在一個jar中。 我已經在C:\\ jboss-4.2.3.GA \\ server \\ default \\ deploy中的jboss服務器中部署了jar,jar的名稱是01addproject.jar(從eclipse導出為EJB JAR文件)

我正在使用另一個項目來編寫客戶端代碼,以查找服務並以一種簡單的方式使用遠程方法。

我感覺該類未在RMI注冊表中注冊,當我將客戶端代碼作為PSVM程序運行時,該類給出了NameNotFoundException。

這是錯誤:

javax.naming.NameNotFoundException: AddRemoteImpl not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
    at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
    at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    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)

(減少為缺乏空間)

包裝結構: 客戶端和EJB代碼的打包結構

AddRemote.java中的代碼

package com.cluster.remote;

import javax.ejb.Remote;

@Remote
public interface AddRemote {

    void m1();
    int add(int x, int y);

}

AddRemoteImpl.java中的代碼

package com.cluster.remote;

import javax.ejb.Stateless;

@Stateless
public class AdddRemoteImpl implements AddRemote {

    @Override
    public void m1() {
        System.out.println("inside m1");
    }

    @Override
    public int add(int x, int y) {

        return x + y;
    }

}

Client.java中的客戶端代碼(psvm程序)

package clientcode;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.cluster.remote.AddRemote;

public class Client {

    /**
     * @param args
     */
    public static void main(String[] args) {

         try {
            AddRemote remote =  (AddRemote) getInitialContext().lookup("AddRemoteImpl/remote");

            System.out.println("The alue form the session bean is " + remote.add(3, 5));
            System.out.println("Added Successfully");



        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static Context getInitialContext() throws NamingException{

        Hashtable hashtable = new Hashtable();
        hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        hashtable.put(Context.PROVIDER_URL, "localhost:1099");
        Context context = new InitialContext(hashtable);


        return context;
    }

}

EJB在綁定時沒有被導出,因此它被序列化為本身而不是它的存根,因此客戶端查找未能加載AddRemoteImpl類,這是合理的,因為客戶端不應該擁有它。 它的構建/聲明/部署方式出了問題,無法進一步解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM