客户端如何知道EJB bean实现在ejb3中是远程的还是本地的 [英] How does client know the EJB bean implementation is remote or local in ejb3

查看:125
本文介绍了客户端如何知道EJB bean实现在ejb3中是远程的还是本地的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是EJB3的新手。我想知道客户端如何知道EJB bean实现是在远程还是本地。当我在客户端类中使用InitialContext访问Bean时,我想知道该bean是本地的还是远程的?抱歉,如果我要问愚蠢的问题?

I'm a newbie to EJB3. I want to know that how client know the EJB bean implementation is in remote or local. When i access the bean using InitialContext in client class i want to know wether that bean is local or remote? Sorry if I'm asking stupid question?

推荐答案

接口的类型是通过注释确定的。

The type of interface is determined via annotations.


  1. 这些可以放在Interface类声明旁边:

  1. These can be put next to Interface class declaration:

@Local -声明本地业务接口

@Remote -声明一个远程业务接口

@Remote - declares a remote business interface

然后,当EJB扩展此类接口时,它将使用该接口作为本地/远程视图。如果它扩展了多个接口,则它具有多个视图。

Then when an EJB extends such interfaces, it uses the interface as a local/remote view. If it extends multiple interfaces, it has multiple views.

这些可以放在EJB类声明旁边:

These can be put next to EJB class declaration:

@Local(com.example.LocalInterfaceClass)-声明本地业务接口
@Remote(com.example.SomeRemoteInterfaceClass )-声明远程业务接口
@LocalBean -声明无接口视图(完整的bean定义用作接口)

@Local(com.example.LocalInterfaceClass) - declares a local business interface @Remote(com.example.SomeRemoteInterfaceClass) - declares a remote business interface @LocalBean - declares a no-interface view (the full bean definition used as an interface)

如果多个上述批注组合使用,则EJB具有多个接口视图。如果全部省略,则Bean默认为无接口视图。

If multiple of above annotations are used in combination, the EJB has multiple interface views. If all are ommitted, the bean defaults to a no-interface view.

您可以使用JDK内置注释处理在编译期间处理注释(通过javax。注解。处理类和javac命令行选项)。例如。您可以生成代码或设置选项/开关。

You can use JDK inbuilt annotation processing to process annotations during compile time (via javax.annotation.processing classes and javac commandline options). E.g. you could generate code or set options/switches.

您可以在运行时使用反射来确定注释。

You can use reflection to determine annotations at runtime.

可能最干净,最简单的是不进行动态查找&行为,但只是为每个客户端提交本地或远程并硬编码适当的行为。

这篇关于客户端如何知道EJB bean实现在ejb3中是远程的还是本地的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆