0

我正在尝试在 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
4

1 回答 1

1

我还要向这个爆炸的罐子添加什么?

没什么,可以用的。

我已经尝试查找为 FirstEJB/HelloWorldRemote/remote

使用 JBoss,JNDI 名称将是:

<myEarName>/<EJB-Name>/remote

如果未指定,则 EJB-Name 默认为 Bean 名称。因此,在您的情况下,不使用 EAR 包装,JNDI 名称应该是:

HelloWorld/remote

顺便说一下,这应该在部署时记录在服务器日志中。

如果我将查找键入为 HelloWorld/remote,则会收到错误 (...)

用于查找的 JNDI 名称是正确的,此错误是另一个与EJBTHREE-1118非常相似的问题。你能试试 JBoss 4.2.3.GA 吗?

于 2010-10-23T02:21:29.617 回答