2010-10-22 34 views
0

我想在Eclipse中的JBOSS 4.2上開發一個基本的EJB3應用程序我已經在eclipse中創建了一個EJB項目。如何獲取EJB?

以下是我的遠程和本地接口。

package com.test; 
import javax.ejb.Local; 

@Local 
public interface HelloWorldLocal 
{ 
    public String getGreeting(); 
} 

package com.test; 
import javax.ejb.Remote; 

@Remote 
public interface HelloWorldRemote 
{ 
    public String getGreeting(); 
} 

和我的EJB實現

package com.test; 
import javax.ejb.Stateless; 

@Stateless 
public class HelloWorld implements HelloWorldRemote, HelloWorldLocal { 


public HelloWorld() { 
    // TODO Auto-generated constructor stub 
} 

public String getGreeting() { 
    // TODO Auto-generated method stub 
    return "First EJB People"; 
} 

} 

我已經部署了本作中的JBoss的分解JAR,它運行良好。

我的第一個問題是:

還有什麼我已經加入到這個罐子爆炸?

其次我創建了一個獨立的客戶端和加入上述罐子其類路徑

客戶端代碼如下

包com.testejb;

import java.io.FileInputStream; import java.util.Properties;

import javax.naming.InitialContext;

public class TestBean { 

/** 
* @param args 
*/ 
public static void main(String[] args) 
{ 
    // TODO Auto-generated method stub 
     HelloWorldRemote getMess = null; 
     try { 
      Properties props = new Properties(); 
      Properties props = new Properties(); 
      props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); 
      props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming"); 
      props.setProperty("java.naming.provider.url", "localhost:1099"); 

      InitialContext ic = new InitialContext(props); 

      // 


      getMess = (HelloWorldRemote) ic.lookup("HelloWorldRemote/remote"); 
      System.out.println(getMess.getGreeting()); 
    } catch (Exception e) 
    { 
     // TODO: handle exception 
     e.printStackTrace(); 
    } 

} 

}

罐子的名稱是FirstEJB。 我已經嘗試查找FirstEJB/HelloWorldRemote/remote。

但是當我運行程序出現錯誤

javax.naming.NameNotFoundException: HelloWorldRemote not bound 

如果我鍵入查詢作爲的HelloWorld /遠程I得到錯誤

Caused by: java.io.InvalidClassException: org.jboss.ejb3.remoting.BaseRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 1126421850898582900, local class serialVersionUID = -2711693270411201590 

回答

1

別的什麼我要補充到這個爆炸的罐子?

沒什麼,這是可用的。

我試圖爲查找FirstEJB/HelloWorldRemote /遠程

與JBoss,JNDI名稱將是:

<myEarName>/<EJB-Name>/remote 

當EJB-名稱默認爲Bean的名字如果沒有指定。所以你的情況,不使用EAR包裝,JNDI名稱應該是:

HelloWorld/remote 

這應該在服務器日誌在部署時的方式進行記錄。

如果我輸入查找作爲HelloWorld/remote,我得到錯誤(...)

用於查找的JNDI名稱是正確的,這個錯誤是與EJBTHREE-1118看起來非常相似的另一個問題。你可以嘗試使用JBoss 4.2.3.GA嗎?