How To Lookup A Stateless Session Edible Bean Inwards A Managed Bean

Since I e'er forgot how to produce in addition to at that spot are several ways to lookup a Stateless Session bean, I'm writing a spider web log entry here:

Fortunately, the newest containers available today such equally Glassfish 3.1.x in addition to JBoss 7.x, listing all the available services on Startup, simply await at the log.

Here are the unlike ways:
1.) JBoss
public static Object getLocalInterface(String nameEJB) {  InitialContext ctx;  displace {   ctx = (InitialContext) getInitialContext();   supply ctx.lookup(nameEJB);  } select care of (NamingException ex) {   ex.printStackTrace();  }  supply null; }  populace MyBeanLocal getService() {  supply ((MyBeanLocal)Utils.getLocalInterface("workflow/MyBeanBean/local")); } 

2.) Glassfish
a.) Long name:
InitialContext ic = novel InitialContext(); IMyService myService = (IMyService) ic       .lookup("java:global/myProject-ear-1.0.0/myModule/MyService!com.czetsuya.service.MyService"); 
b.) App access
InitialContext ic = novel InitialContext(); IMyService promoService = (IMyService) ic       .lookup("java:app/myProject-ear/myModule/MyService"); 
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.