在EJB 3中使用客户端jar和设计模式 [英] Using the client jar in EJB 3 and design patterns

查看:113
本文介绍了在EJB 3中使用客户端jar和设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是EJB 3的新手,对Google没有提供令人满意的答案有些怀疑。



我正在尝试创建一个框架有一些基类和一些其他应用程序可以使用的实用程序方法。所有应用程序都将部署在同一台服务器上。



当我尝试在eclipse中创建一个新的EJB 3.0项目时,它会询问我是否要创建一个客户端罐子也。这个客户端jar服务的目的是什么?我的ejbmodule作为EAR文件的一部分被添加。那么我真的需要这个客户端jar吗?
我需要创建本地和远程接口吗?或者只是远程接口将会做?



我决定将所有接口保存在一个名为 projCommon 的项目中,而在 projApps中的bean定义即可。 bean类实现的远程接口在projCommon中。所以projApps依赖于projCommon。



我计划使用在projCommon中定义的委托方法来调用bean类。这将意味着projCommon也依赖于projApps,rt?导致循环依赖。



EJB是如何直接注入的?



如果你真的很有帮助可以为我的怀疑提供解释。

解决方案


当我试图创建一个新的eclipse中的EJB
3.0项目,它询问我是否也要创建一个客户端jar。这个客户端jar提供什么
目的?


一个EJB客户端JAR文件是一个可选的JAR文件,可以包含所有客户端程序需要使用EJB JAR文件中包含的企业bean的客户端视图的类文件。如果您决定不为EJB模块创建客户端JAR文件,则所有客户端接口类都将位于EJB JAR文件中。


我的ejbmodule作为
EAR文件的一部分添加。那么我真的需要这个
客户端jar?


您真的不需要EJB客户端,它只是提供一个更容易的包装来使用客户端的EJB。


我需要创建本地和
远程接口吗?还是只是远程
接口呢?


如果所有EJB都在同一个EAR中,那么您可以使用本地接口,如果不需要远程接口。本地接口效率更高,调用完成为参考。

某些容器(即WebSphere)将在运行时为您进行优化,并在可能的情况下自动调用本地接口。我决定把所有的接口
保留在名为projCommon的项目和projApps中的
bean定义中。 bean
类实现的
远程接口在projCommon中。
所以projApps依赖于
projCommon。


我会让我的项目按功能区域组织。在功能区域之外的本地电话和远程功能区域之间进行本地呼叫。这样,您可以稍后将要部署在不同服务器上的功能分拆。它还保持代码更模块化。这也避免了任何循环依赖。


EJB是如何直接注入
的?


它的工作方式并不重要,这将由容器完成。 J2EE的全部要点是抽象出如何。



根据 http://www.developer.com/print.php/3650661



EJB 3容器提供了各种各样的设备资源类型分为无状态会话bean。通常,为了从客户端应用程序执行用户任务或处理请求,会话bean中的业务方法需要一种或多种类型的资源。这些资源可以是其他会话bean,数据源或消息队列。



无状态会话bean尝试使用的资源可以使用注释或部署描述符注入。资源可以通过注释实例变量或setter方法的注释来获取。


I'm new to EJB 3 and pretty confused with some doubts which Google didn't provide with a satisfactory answer.

I'm trying to create a framework with some base classes and some utility methods which my other applications can use. All applications are to be deployed on the same server.

When I'm trying to create a new EJB 3.0 project in eclipse, it asks if I want to create a client jar also. What purpose does this client jar serve? My ejbmodule is added as a part of the EAR file. So do I really need this client jar? Do I need to create both local and remote interfaces? Or just remote interfaces will do?

I decided to keep all the interfaces in a project called projCommon and the bean definitions in projApps. The remote interfaces which the bean classes implement are in projCommon. So projApps is dependent on projCommon.

I plan to use a delegate method defined in projCommon to invoke the bean classes. That will mean that projCommon is also dependent on projApps, rt? And lead to a circular dependency.

How exactly are EJB's directly injected?

Would be really helpful if you can kindly provide an explanation to my doubts.

解决方案

When I'm trying to create a new EJB 3.0 project in eclipse, it asks if I want to create a client jar also. What purpose does this client jar serve?

An EJB client JAR file is an optional JAR file that can contain all the class files that a client program needs to use the client view of the enterprise beans that are contained in the EJB JAR file. If you decide not to create a client JAR file for an EJB module, all of the client interface classes will be in the EJB JAR file

My ejbmodule is added as a part of the EAR file. So do I really need this client jar?

You do not really need the EJB Client it just provides an easier packaging to use the EJBs from a client.

Do I need to create both local and remote interfaces? Or just remote interfaces will do?

If all your EJBs are in the same EAR then you can use local interfaces, if not you need remote interfaces. Local interfaces are more efficient, the calls are done be reference.
Some Containers (i.e. WebSphere) will optimize this at runtime for you and automatically call local interfaces if it is possible.

I decided to keep all the interfaces in a project called projCommon and the bean definitions in projApps. The remote interfaces which the bean classes implement are in projCommon. So projApps is dependent on projCommon.

I would keep my projects organized by functional areas. Make local calls within the functional areas and remote ones outside of the functional areas, This allows you to later split the functionality to be deployed on different servers to scale it. It also keeps the code more modular. This also avoids any circular dependencies.

How exactly are EJB's directly injected?

The how it works does not matter, That is going to be done by the container. The whole point of J2EE is to abstract out the how.

As per http://www.developer.com/print.php/3650661:

EJB 3 containers provide the facilities to inject various types of resources into stateless session beans. Typically, in order to perform user tasks or process requests from client applications, the business methods in the session bean require one or more types of resources. These resources can be other session beans, data sources, or message queues.

The resources that the stateless session bean is trying to use can be injected using annotations or deployment descriptors. Resources can be acquired by annotation of instance variables or annotation of the setter methods.

这篇关于在EJB 3中使用客户端jar和设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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