如何访问EJB?

发布于 2024-09-28 17:10:12 字数 2360 浏览 7 评论 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添加到其类路径中

客户端代码如下:

package 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

I am trying to develop a Basic EJB3 application on JBOSS 4.2 in Eclipse

I have created an EJB project in eclipse.

The following are my remote and local interfaces.

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();
}

and my ejb implementation is

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";
}

}

I have deployed this as an exploded JAR in JBoss and it runs fine.

My first question is:

What else do I have to add to this exploded jar ?

Secondly I created a stand alone client and added the above jar to its classpath

The client code is as follows

package 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();
    }

}

}

The name of the jar is FirstEJB.
I have tried the look up as FirstEJB/HelloWorldRemote/remote.

But when I run the program I get the error

javax.naming.NameNotFoundException: HelloWorldRemote not bound

If I type the lookup as HelloWorld/remote i get the error

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七分※倦醒 2024-10-05 17:10:12

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

没什么,可以用。

我已尝试查找 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 吗?

What else do I have to add to this exploded jar ?

Nothing, it's usable.

I have tried the look up as FirstEJB/HelloWorldRemote/remote

With JBoss, the JNDI name will be:

<myEarName>/<EJB-Name>/remote

Where the EJB-Name defaults to the Bean name if not specified. So in your case, without using an EAR packaging, the JNDI name should be:

HelloWorld/remote

This should be logged in the server logs at deployment time by the way.

If I type the lookup as HelloWorld/remote I get the error (...)

The JNDI name used for the lookup is correct, this error is another problem that looks very similar to EJBTHREE-1118. Could you try with JBoss 4.2.3.GA?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文