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?

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

4 个解决方案

#1


119

The rules are (from memory):

规则是(根据记忆):

  1. Bean has a @LocalBean annotation -> bean has a no-interface view
  2. Bean有一个@LocalBean注释——> Bean有一个无接口视图
  3. Bean has a @Local annotation -> bean has a local view
  4. Bean有一个@Local注释—> Bean有一个本地视图。
  5. Bean has a @Remote annotation -> bean has a remote view
  6. Bean有一个@Remote注释——> Bean有一个远程视图
  7. Bean has no view annotations, but directly implements an interface which has a @Local annotation -> bean has a local view
  8. Bean没有视图注释,但是直接实现了一个接口,接口有一个@Local注释——> Bean有一个本地视图
  9. Bean has no view annotations, but directly implements an interface which has a @Remote annotation -> bean has a remote view
  10. Bean没有视图注释,但是直接实现了一个接口,接口有一个@Remote annotation——> Bean有一个远程视图
  11. Bean has no view annotations, but directly implements an interface which has no view annotations -> bean has a local view
  12. Bean没有视图注释,但是直接实现了一个没有视图注释的接口——> Bean有一个本地视图
  13. Bean has no view annotations, and implements no interfaces -> bean has a no-interface view
  14. Bean没有视图注解,没有接口——> Bean有一个无接口视图。

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.

因此,使用@LocalBean和完全不使用注释都是获得无接口视图的方法。如果您只想要一个无接口视图,那么最简单的事情就是不要注释。如果您没有实现任何接口。

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:

@LocalBean存在的部分原因是向同样具有接口视图的bean添加无接口视图。我想规范作者们脑海中最重要的场景是这样的:

@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.

您希望在本地公开这两个方法,但只远程公开粗粒度的getPreferences()。您可以使用该方法声明远程接口,然后在bean类上使用@LocalBean。如果没有它,您将不得不编写一个毫无意义的本地接口来在本地公开这两个方法。

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.

或者,换个角度来看,@LocalBean之所以存在,是因为存在一个无接口视图,而无注释选项作为一个方便的快捷方式存在。

更多相关文章

  1. springMVC使用html视图配置详解
  2. 怎么用java 实现两个web service之间调用各自的接口 实现数据的
  3. 接口之命令模式
  4. 关于Java中接口继承接口
  5. php 调用java 接口
  6. 深入理解Java Callable接口
  7. 自定义视图无法工作,直到我触摸屏幕
  8. 做一个没有视图的零食吧?

随机推荐

  1. php 修改、增加xml结点属性的实现代码
  2. php操作xml
  3. Java如何读取XML文件 具体实现
  4. Java中构造、生成XML简明教程
  5. XML和YAML的使用方法
  6. 在java中使用dom4j解析xml(示例代码)
  7. PlayFramework完整实现一个APP(十四)
  8. java解析XML几种方式小结
  9. XML 非法字符(转义字符)
  10. PlayFramework完整实现一个APP(九)