EJB 3.1 @LocalBean vs no annotation [英] EJB 3.1 @LocalBean vs no annotation

查看:172
本文介绍了EJB 3.1 @LocalBean vs no annotation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解本地视图,远程视图和无界面视图之间的区别。我只是不明白无视图(无注释)和无界面视图之间的区别是什么。还有为什么要用 @Local 注释我的界面?如果我没有注释接口,有什么区别吗?

解决方案

规则是(从内存) :


  1. Bean有一个 @LocalBean 注释 - > bean有一个无界面查看

  2. Bean有一个 @Local 注释 - > bean有本地视图

  3. Bean有一个 @Remote 注释 - > bean有一个远程视图

  4. Bean没有视图注释,但是直接实现一个接口, @Local注释 - > bean具有本地视图

  5. Bean没有视图注释,但是直接实现了一个具有@Remote注释的界面 - > bean具有远程视图

  6. Bean没有视图注释,但是直接实现没有视图注释的接口 - > bean具有本地视图

  7. Bean没有视图注释,并且不实现接口 - > bean具有无界面视图

所以,使用 @LocalBean 并且根本不使用任何注释都是获取无界面视图的方式。如果你只想要一个无界面的视图,那么最简单的就是不要注释。如果您还没有实现任何接口。



存在原因的一部分原因 @LocalBean 接口视图到一个也有一个接口视图的bean。我想象,规范作者的头脑中最重要的一个场景是一个你拥有如下的bean:

  @Stateless 
public class UserPreferences {
public String getPreference(String preferenceName);
public Map< String,String>的getPreferences();
}

您希望在本地公开这两种方法,但只有粗糙度 getPreferences()远程。您可以通过仅使用该方法声明远程接口,然后在bean类上轻敲 @LocalBean 来实现。没有它,你必须写一个无意义的本地界面,只是为了在本地公开这两种方法。



或者,另外看看, @LocalBean 存在,因为有一个像无界面视图这样的东西,没有注释选项作为一个方便的快捷方式存在。


I understand the difference between local view, remote view and no-interface view. I just don't understand what is the difference between "no view" (no annotation) and no-interface view. And also why should I annotate my interface with @Local? What if I don't annotate the interface in at all, is there a difference?

解决方案

The rules are (from memory):

  1. Bean has a @LocalBean annotation -> bean has a no-interface view
  2. Bean has a @Local annotation -> bean has a local view
  3. Bean has a @Remote annotation -> bean has a remote view
  4. Bean has no view annotations, but directly implements an interface which has a @Local annotation -> bean has a local view
  5. Bean has no view annotations, but directly implements an interface which has a @Remote annotation -> bean has a remote view
  6. Bean has no view annotations, but directly implements an interface which has no view annotations -> bean has a local view
  7. Bean has no view annotations, and implements no interfaces -> bean has a no-interface view

So, using @LocalBean and using no annotation at all are both ways of getting a no-interface view. If you just want a no-interface view, then the simplest thing is not to annotate. Provided you're not also implementing any interfaces.

Part of the reason @LocalBean exists to add a no-interface view to a bean which also has an interface view. I imagine the scenario uppermost in the spec authors' minds was one where you have a bean like:

@Stateless
public class UserPreferences {
    public String getPreference(String preferenceName);
    public Map<String, String> getPreferences();
}

Where you would want to expose both methods locally, but only the coarser-grained getPreferences() remotely. You can do that by declaring a remote interface with just that method, then just slapping @LocalBean on the bean class. Without it, you'd have to write a pointless local interface just to expose both methods locally.

Or, to look at it another way, the @LocalBean exists because there is such a thing as a no-interface view, and the no-annotation option exists as a handy shortcut.

这篇关于EJB 3.1 @LocalBean vs no annotation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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