How to lookup a Stateless Session bean in a Managed Bean
Since I always forgot how to do and there are several ways to lookup a Stateless Session bean, I'm writing a blog entry here: Fortunat...
https://www.czetsuyatech.com/2012/12/javaee-lookup-stateless-session-bean.html
Since I always forgot how to do and there are several ways to lookup a Stateless Session bean, I'm writing a blog entry here:
Fortunately, the newest containers available today such as Glassfish 3.1.x and JBoss 7.x, list all the available services on Startup, just look at the log.
Here are the different ways:
1.) JBoss
2.) Glassfish
a.) Long name:
Fortunately, the newest containers available today such as Glassfish 3.1.x and JBoss 7.x, list all the available services on Startup, just look at the log.
Here are the different ways:
1.) JBoss
public static Object getLocalInterface(String nameEJB) {
InitialContext ctx;
try {
ctx = (InitialContext) getInitialContext();
return ctx.lookup(nameEJB);
} catch (NamingException ex) {
ex.printStackTrace();
}
return null;
}
public MyBeanLocal getService() {
return ((MyBeanLocal)Utils.getLocalInterface("workflow/MyBeanBean/local"));
}
2.) Glassfish
a.) Long name:
InitialContext ic = new InitialContext();
IMyService myService = (IMyService) ic
.lookup("java:global/myProject-ear-1.0.0/myModule/MyService!com.czetsuya.service.MyService");
b.) App access
InitialContext ic = new InitialContext();
IMyService promoService = (IMyService) ic
.lookup("java:app/myProject-ear/myModule/MyService");




Post a Comment