gpt4 book ai didi

java - "LocalBean"和 "Remote"都可以在一个 bean 上注释吗?

转载 作者:搜寻专家 更新时间:2023-11-01 03:09:40 27 4
gpt4 key购买 nike

我知道这听起来可能很初级,但我想知道以下单例 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com