- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我知道这听起来可能很初级,但我想知道以下单例 bean:
@Startup
@Singleton
@LocalBean
public class MyServiceBean {
public String sayHello() { return "Hello"; }
}
现在我认为“远程”客户端可能需要使用这个 bean,所以我想为这个 bean 添加一个远程接口(interface):
@Remote
public interface MyService {
String sayHello();
}
我可以让我的 bean 实现新的远程接口(interface)吗?
如果“MyServiceBean”实现了“MyService”远程接口(interface),它将成为一个带有“remote-interface-view”的bean ...但是我在网上搜索后,你们都说一个注解为“LocalBean”的bean是一个“无界面 View ”。
这样可以吗?还是我应该创建一个本地接口(interface)并删除 LocalBean 注释?
更深入的思考...如果“远程 View ”、“本地 View ”和“无接口(interface) View ”是 3 种类型的 View ,它们都可以存在于一个 bean 中……?我可以有一个实现所有这些的 bean 吗?
@Local
@Remote
@LocalBean
public class Possible implements PosLoca, PosRemote {}
....我真的很困惑...
最佳答案
是的,一个 bean 可以暴露多个 View (远程业务、本地业务、无接口(interface))。
组件可以相同 - 您只需添加另一种访问方式即可。
看看 EJB 3.1 FR 规范:
4.4.2.2 session bean 公开多个客户端 View (第 86 页)。
package com.acme;
@Singleton(name="Shared")
@LocalBean
@Remote(com.acme.SharedRemote.class)
public class SharedBean { ... }
请注意 - 我认为您发布的示例不会开箱即用。您正在使用 @Remote
和 @Local
而未指定接口(interface)引用。我不认为容器现在将哪个接口(interface)是什么。指定 @Remote(clazz)
或将接口(interface)本身注释为 @Remote
。
关于java - "LocalBean"和 "Remote"都可以在一个 bean 上注释吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13394002/
我正在关注 EJB cookbook ,来自 packt,使用以下代码: package packt; import javax.ejb.Stateless; import javax.ejb.Loc
我正在努力掌握 EJB3Unit ,对 EJB 3.1 无状态 bean 进行单元测试,但 EJB3Unit 提示,因为我的 EJB 没有“业务接口(interface)”。但我认为所有这些“业务接口
我了解本地 View 、远程 View 和无接口(interface) View 之间的区别。我只是不明白“无 View ”(无注释)和无界面 View 有什么区别。还有为什么我要使用 @Local
我知道这听起来可能很初级,但我想知道以下单例 bean: @Startup @Singleton @LocalBean public class MyServiceBean { public
我有以下配置: 一个 GF 上的 1 个 EAR,包含 2 个带有 EJB 组件的 EJB-JAR。 另一个 Glassfish 服务器(=> 其他 JVM)上的 1 个 WAR,其中包含访问 EJB
我是一名优秀的程序员,十分优秀!