简体   繁体   中英

Injecting a remote EJB in a managedBean

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 :(

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM