我正在尝试在 Eclipse 中的 JBOSS 4.2 上开发基本 EJB3 应用程序
我在 Eclipse 中创建了一个 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,它运行良好。
我的第一个问题是:
我还要向这个爆炸的罐子添加什么?
其次,我创建了一个独立客户端并将上面的 jar 添加到它的类路径中
客户端代码如下
包 com.testejb;
导入 java.io.FileInputStream;导入 java.util.Properties;
导入 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();
}
}
}
jar 的名称是 FirstEJB。我已经尝试查找为 FirstEJB/HelloWorldRemote/remote。
但是当我运行程序时,我得到了错误
javax.naming.NameNotFoundException: HelloWorldRemote not bound
如果我将查找键入为 HelloWorld/remote,则会收到错误消息
Caused by: java.io.InvalidClassException: org.jboss.ejb3.remoting.BaseRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 1126421850898582900, local class serialVersionUID = -2711693270411201590