[英]If EJB exposed @Remote interface, but you inject the EJB bean instead of its Remote interface, will this trigger a remote or local invocation?
I have a EJB bean that exposed to two interface like below: Local interface is for my web app, and Remote interface is for my App Client 我有一个暴露于两个接口的EJB bean,如下所示:本地接口用于我的Web应用程序,Remote接口用于我的App Client
@Stateless
public class CoreMainEJB implements CoreMainEJBRemote, CoreMainEJBLocal {
//...
}
so my App Client looks as below. 所以我的App Client如下所示。 Remote method invocation is happened in this case
在这种情况下发生远程方法调用
public class Main {
@EJB
private static CoreMainEJBRemote coreEJBRemote;
public static void main(String[] args) {
coreEJBRemote.process(args[0]);
}
}
From my web app I invoke as below. 从我的网络应用程序,我调用如下。 Local method invocation is happened in this case
在这种情况下发生本地方法调用
@ManagedBean
@RequestScoped
public class DisplayInbound {
@EJB
private CoreMainEJBLocal coreMainEJBLocal;
public void processPackages() {
coreMainEJBLocal.process(...);
}
}
So here is my question, If the EJB only exposed @Remote interface, but in your web app, you inject the EJB bean directly instead of its Remote interface, will this trigger a remote invocation or local invocation? 所以这是我的问题, 如果EJB只暴露了@Remote接口,但是在您的Web应用程序中,您直接注入EJB bean而不是其Remote接口,这会触发远程调用还是本地调用? For example:
例如:
@Stateless
public class CoreMainEJB implements CoreMainEJBRemote{
//...
}
and in the web app, I do this 在网络应用程序中,我这样做
@EJB
private CoreMainEJB coreMainEJB;
public void processPackages() {
coreMainEJB.process(...); //Is this local or remote invocation here?
}
The last example as given will simply not work. 给出的最后一个例子根本不起作用。 Since
CoreMainEJB
already implements a remote interface, the container will not create a No-Interface view. 由于
CoreMainEJB
已实现远程接口,因此容器不会创建无接口视图。 This is exactly the case for which @LocalBean
is intended. 这正是
@LocalBean
用途。
So to answer the question ' Is this local or remote invocation here? 所以回答这个问题' 这是本地或远程调用吗? ' directly: it's neither.
'直接:它既不是。 The container will not be able to inject anything and probably barf out at the deployment stage.
容器将无法注入任何东西,并且可能在部署阶段进行barf。
If you define your bean as: 如果将bean定义为:
@Stateless
@LocalBean
public class CoreMainEJB implements CoreMainEJBRemote{
//...
}
Then local semantics will apply here: 然后本地语义将适用于此:
@EJB
private CoreMainEJB coreMainEJB;
public void processPackages() {
coreMainEJB.process(...); // Local semantics
}
(assuming the above code fragment is in the same application as where CoreMainEJB
is defined of course) (假设上面的代码片段与
CoreMainEJB
定义的应用程序在同一个应用程序中)
无接口调用是本地调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.