【发布时间】:2013-11-15 10:13:51
【问题描述】:
我想知道你们中是否有人曾经远程调用过 EJB。这是我的场景:
我在自己的 jar 文件中有一个远程接口包。然后是依赖于前一个的 EJB 模块(另一个 jar 文件)将接口实现为 @Stateless 会话 bean。
我已经在 JBOSS 5.1.0.GA 中部署了 EJB 模块。当我尝试从 Eclipse 中调用 EJB 时,返回的对象未被识别为接口类型。下面是不同的java代码。
业务界面:
@Remote
public interface RemoteBusinessInterface
{
public CustomerResponse getCustomerData( final CustomerRequest customerRequest );
}
在自己的jar文件中实现类包:
@Stateless
public class RemoteEJBBean implements RemoteBusinessInterface
{
public CustomerResponse getCustomerData( final CustomerRequest customerRequest )
{...
以及调用远程EJB的代码:
public class TestRemoteEjb
{
public static void main( final String[] args )
{
try
{
InitialContext initialContext = new InitialContext();
Object ref = initialContext.lookup( "java:/CustomerServiceBean/remote" );
System.out.println( ref );
if ( ref instanceof RemoteBusinessInterface )
{
System.out.println( "RemoteBusinessInterface" );
}
else
{
System.out.println( "Not of type RemoteBusinessInterface" );
}
}
catch ( NamingException e )
{
e.printStackTrace();
}
}
}
输出如下:
参考类名称:代理:com.tchouaffe.remote.interfaces.RemoteBusinessInterface 类型:ProxyFactoryKey 内容:ProxyFactory/remote-ejb-1.0.0-SNAPSHOT/CustomerServiceBean/CustomerServiceBean/remote 类型:EJB 容器名称 内容:jboss.j2ee:jar=remote-ejb-1.0.0-SNAPSHOT.jar,name=CustomerServiceBean,service=EJB3 类型:代理工厂是本地的 内容:假 类型:远程业务接口 内容:com.tchouaffe.remote.interfaces.RemoteBusinessInterface 类型:远程主机 URL 内容:socket://127.0.0.1:3873/
不是 RemoteBusinessInterface 类型
我一直想知道为什么返回的对象是 RemoteBusinessInterface 以外的类型。
感谢您的帮助。
埃德蒙
【问题讨论】:
-
如果您将查找结果转换为 RemoteBusinessInterface,您会得到一个异常,不是吗?
-
是的,确实如此。任何将结果转换为 RemoteBusinessInterface 的尝试都会引发异常。
标签: java eclipse jakarta-ee jboss