什么是EJB中的本地/远程和无界面视图? [英] What is local/remote and no-interface view in EJB?

查看:180
本文介绍了什么是EJB中的本地/远程和无界面视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力了解目的,为什么我们需要EJB中不同的客户端视图。有人可以尝试解释吗?

解决方案

远程客户端视图



<当您的EJB及其客户端将处于分布式环境中时,这意味着EJB和客户端将驻留在单独的Java虚拟机上。示例:承载在WebSphere Application Server上的EJB和使用Tomcat服务器上托管的EJB API的Servlet。



本地客户端视图



只有确保其他企业bean或客户端才能在单个JVM中寻址bean。示例,EJB以及部署在同一个WebSphere服务器上的Servlet。



无界面视图



与本地客户端视图几乎相同,但有差异。在这种情况下,您的bean类不需要实现客户端视图接口。 bean类的所有公共方法都会自动暴露给调用者。无界面视图始终通过注入或JNDI查找获取EJB引用 - 就像本地或远程视图一样;但EJB引用的Java类型是bean类类型,而不是本地接口的类型。这是作为Java EE6的一部分引入的便利。



本地客户端视图和无界面视图之间的区别



如果没有接口视图,客户端和目标bean必须打包在同一应用程序(EAR)中。在本地视图的情况下,客户端可以打包在与企业应用程序不同的应用程序中。因此,这样可以更好地灵活地组合您的组件。



根据您的API使用情况,您可以使用本地客户端视图vs无界面视图。



原因


$ b在未来的规格中,无接口视图很可能会收到灵活的功能。 $ b

历史或其他方式,希望使用EJB服务的客户端应该查找容器上的bean(具有某些初始上下文)。这是因为所有调用都是通过容器提供的特殊EJB引用(代理)来进行的。这允许容器提供所有其他bean服务,如池,容器管理的事务等。因此,客户端无法使用 new 运算符显式实例化EJB。客户端视图是通过客户端可以访问的某些接口提供的。服务器端的代理实现是基于这些接口完成的。不同的客户端视图被定义为如上所述的不同的部署方案。




I am trying to understand what the purpose and why we need the different client views in EJB. Could someone try to explain?

解决方案

Remote client view

When your EJB and its clients will be in a distributed environment - meaning EJBs and clients will reside on separate Java virtual machines. Example : EJBs hosted on a WebSphere Application Server and Servlets that consume EJB APIs hosted on a Tomcat server.

Local client view

Only when it is guaranteed that other enterprise beans or clients will only address the bean within a single JVM. Example, EJBs as well as the Servlets deployed on the same WebSphere server.

No-Interface view

Is almost same as local client view, but there are differences. Your bean class is not required to implement client view interfaces in this case. All public methods of the bean class are automatically exposed to the caller. no-interface view always acquires an EJB reference - just like local or remote views - either through injection or JNDI lookup; but, Java type of the EJB reference is the bean class type rather than the type of a local interface. This is a convenience introduced as part of Java EE6.

Difference between local client view and no-interface view

In case of no-interface view, the client and the target bean must be packaged in the same application (EAR). In case of local view, client can be packaged in a separate application than the enterprise application. So, this gives more flexibility in terms of fine-graining your components.

You may use local client view vs no-interface view depending on your API usage scenario. It is very likely for no-interface view to receive flexible features in future specs.

Reason

Historically or otherwise, a client wishing to use EJB services was supposed to "look up" the bean on the container ( with certain initial contexts ). That was because all invocations are made through a special EJB reference(proxy) provided by the container. This allows the container to provide all the additional bean services such as pooling, container-managed transactions etc. So, a client can not explicitly instantiate an EJB with new operator. The client view is provided via certain interfaces that the client would have access to. The proxy realization at server side is done based on these interfaces. Different client views are defined to suite different deployment scenarios as mentioned above.

这篇关于什么是EJB中的本地/远程和无界面视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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