我正在尝试在 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 里?
其次,我创建了一个独立的客户端并将上述 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
最佳答案
What else do I have to add to this exploded jar ?
没什么,可以用。
I have tried the look up as FirstEJB/HelloWorldRemote/remote
对于 JBoss,JNDI 名称将为:
<myEarName>/<EJB-Name>/remote
如果未指定,EJB-Name 默认为 Bean 名称。因此,在您的情况下,如果不使用 EAR 包装,JNDI 名称应该是:
HelloWorld/remote
顺便说一句,这应该在部署时记录在服务器日志中。
If I type the lookup as HelloWorld/remote I get the error (...)
用于查找的 JNDI 名称是正确的,此错误是另一个看起来与 EJBTHREE-1118 非常相似的问题。 。您可以尝试使用 JBoss 4.2.3.GA 吗?
关于java - 如何访问EJB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3994332/