在managedBean中注入远程EJB(Injecting a remote EJB in a managedBean)

系统教程 行业动态 更新时间:2024-06-14 16:57:18
在managedBean中注入远程EJB(Injecting a remote EJB in a managedBean)

从x时间开始,我就陷入了如何在JSF应用程序的托管bean中注入远程EJB的问题。 我已经创建了一个简单的java应用程序,并且我已经使用查找来注入远程EJB ......它可以工作。 但是当我来到网络应用程序时,我真的不知道该怎么办!!!

这是我的EJB代码:

@Stateless public class Hello implements HelloRemote { @Override public String sayHello(String name) { return "Hello, "+name; } }

远程接口是

@Remote public interface HelloRemote { public String sayHello(String name); }

在我的Web应用程序中,我创建了我管理的bean:

@ManagedBean public class MyBean { @EJB HelloRemote helloRemote; }

但它不工作:(

I'm stuck since x time on how to inject a remote EJB in a managed bean of a JSF application. I've created a simpl java application and i've come to inject the remote EJB with the lookup... and it works. but when i come to the web application i really don't know what to do !!!

here is my EJB code:

@Stateless public class Hello implements HelloRemote { @Override public String sayHello(String name) { return "Hello, "+name; } }

the Remote interface is

@Remote public interface HelloRemote { public String sayHello(String name); }

in my web application i vre created i managed bean :

@ManagedBean public class MyBean { @EJB HelloRemote helloRemote; }

BUT IT DOESN'T WORK :(

最满意答案

如果要在本地公开EJB,则必须在接口上使用@Local 。

如果要在本地和远程公开,则必须创建2个接口,一个使用@Local ,另一个使用@Remote 。

如果您的JSF ManagedBean(MyBean)在本地运行,即, 在与EJB相同的App服务器上运行,您可以使用@EJB直接注入它。

如果您的JSF ManagedBean在不同的服务器上运行,则必须使用JNDI Registry来查找和访问EJB。

If you want to expose EJB locally you have to use @Local on Interface.

If you want to expose both locally and remotely you have to created 2 Interfaces, one with @Local and one with @Remote.

If your JSF ManagedBean(MyBean) is running locally ie.,Running on same App server as EJB you can directly inject it using @EJB.

If your JSF ManagedBean is running on different server, you have to use the JNDI Registry to look up and access the EJB.

更多推荐

EJB,public,应用,application,bean,电脑培训,计算机培训,IT培训"/> <meta name=&quo

本文发布于:2023-04-12 20:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/fbdfa212eb474c7372d6c44e23d5b02e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:EJB   managedBean   remote   Injecting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!