我想構建一個simpmle Hello world類型的EJB 2.1應用程序。這個應用程序的預期運行時間應該是Jboss 5.1.0。 這是我寫的代碼。
EJB配置文件:
EJB/TestEJBInterfaceBean com.TestEJB.TestEJBInterfaceHome com.TestEJB.TestEJBInterfaceRemote com.TestEJB.TestEJBInterfaceBean 無國籍 集裝箱
Home接口:
import javax.ejb.EJBHome;
public interface TestEJBInterfaceHome extends EJBHome {
public TestEJBInterfaceRemote create() throws java.rmi.RemoteException,
javax.ejb.CreateException;
}
Remote Interface:
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface TestEJBInterfaceRemote extends EJBObject {
public String ping(String version) throws RemoteException;
}
Bean類:
import java.rmi.RemoteException;
import java.util.Date;
import org.jboss.logging.Logger;
public class TestEJBIInterfaceBean extends BaseSessionBean implements TestEJBIInterfaceRemote{
private static final long serialVersionUID = 1L;
final Logger log = Logger.getLogger(TestEJBIInterfaceBean.class);
public String ping(String arg0) throws RemoteException {
String response = this.getClass().getSimpleName() + " pinged @ " + new Date().getTime();
log.info(response);
return response;
}
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub
}
public EJBHome getEJBHome() throws RemoteException {
// TODO Auto-generated method stub
return null;
}
public Handle getHandle() throws RemoteException {
// TODO Auto-generated method stub
return null;
}
public Object getPrimaryKey() throws RemoteException {
// TODO Auto-generated method stub
return null;
}
public boolean isIdentical(EJBObject arg0) throws RemoteException {
// TODO Auto-generated method stub
return false;
}
public void remove() throws RemoteException, RemoveException {
// TODO Auto-generated method stub
}
}
測試客戶端:
public class TestEJBInterfaceClientTest {
/**
* @param args
*/
public static void main(String[] args) {
try {
Context ctx = new InitialContext();
TestEJBInterfaceRemote obj = (TestEJBInterfaceRemote)ctx.lookup("ejb/TestEJBInterfaceBean");
System.out.println(obj.ping("12345"));
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
當我運行客戶端,我收到以下錯誤:
Exception in thread "main" java.lang.ClassCastException: $Proxy0 cannot be cast to com.TestEJB.TestEJBInterfaceRemote
at TestEJBInterfaceClientTest.main(TestEJBInterfaceClientTest.java:21)
該錯誤似乎表明t演員陣容錯了,但我懷疑演員與這個錯誤無關。 (我試圖轉換到TestEJBInterfaceHome,但我得到相同的錯誤)。我的懷疑實際上是在應用程序的版本中。
問題
- 是否有JBoss是治療爲一個EJB3應用程序的任何可能性?看看配置文件,我沒有指定這是一個EJB2.1,所以也許這是導致一個問題?
- 有什麼方法可以找出從
ctx.lookup
調用中返回什麼類型?我試過getClass().getName
,getClass().getCanonicalName()
,所有我回來的是$proxy0, $proxy20
等 - 我是否錯過了明顯的東西?