3

我的耳朵具有以下结构:

  • 出现
    • 应用程序 API
    • 应用程序-ejb
    • 应用程序网络

app-web 和 app-ejb 依赖于 app-api 模块,但它们并不相互依赖。

接口 (app-api) 和 bean (app-ejb):

package sample.services;

@Remote
public interface SampleServiceRemote{
    ...
}


package sample.services;

@Local
public interface SampleService extends SampleServiceRemote{
    ...
}

package sample.services;

@Stateless
@Local(SampleService.class)
@Remote(SampleServiceRemote.class)
public class SampleServiceBean implements SampleService{
    ...
}

我想从 app-api 和 app-web 模块中查找具有本地和远程接口的 SampleServiceBean:

InitialContext ic = new InitialContext();

//Case #1: Works fine without any exception
SampleServiceRemote service = (SampleServiceRemote) ic.lookup("java:global/app-ear/app-ejb/SampleServiceBean!sample.services.SampleServiceRemote");

//Case #2: Throws ClassCastException
SampleService service = (SampleService) ic.lookup("java:global/app-ear/app-ejb/SampleServiceBean!sample.services.SampleService");

当我在 WildFly 服务器 (9.0.1.Final) 上查找本地接口时,它会返回一个 sample.services.SampleService$$$view4 对象,该对象无法转换为 SampleService。

我在 Glassfish 4.1 上尝试了相同的应用程序,但它运行良好。返回的对象:

  • 远程:javax.naming.Reference(可转换为 SampleServiceRemote)
  • 本地:com.sun.ejb.containers.JavaGlobalJndiNamingObjectProxy(可转换为 SampleService)

有人可以告诉我,我怎样才能在 WildFly 上实现相同的行为?

更新 1

我尝试了 user140547 推荐的解决方案。它没有用。它返回相同的类:/。

更新 2

经过几天的尝试和谷歌搜索,我决定从我的项目中排除 EJB。它们不是必需的,没有它们我也可以做到。问题是,当我尝试将 bean 用作 Local 时,Wildfly 总是给我一些 Proxy 类,这些类不能转换为 Local 接口(也不能转换为 Remote 接口)。我只能使用 @EJB 注释获得本地引用,但在 EJB 模块之外它只返回一个空:/。

4

1 回答 1

0

看到这个问题:access a Local Session Bean from another EAR? 似乎从另一个应用程序访问本地 bean 是 EJB 的一个可选功能,因此它可能适用于 Glassfish,但不适用于 Wildfly。

另一方面,您的问题是关于 EAR。@Remote但是,如果此答案也适用于您,则与所提供的界面无关。

于 2015-10-31T18:13:47.653 回答