从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
发布评论