Fuzzy name EJB bean JNDI under Weblogic
I made a small example using weblogic 10.3.6 and EJB 3.0. Define a SimpleService class, define weblogic-ejb-jar.xml to map the SimpleService class to a JNDI name, package it as an EJB component in an EAR file, and deploy it to the server. The deployment is successful and I see an ejb bean named SimpleServiceBean. After that, using standalone app, connect to webloigc server via InitialContext with all required environment attributes, I will try to find this bean. I assume it will be available under the name ejb / SimpleService, but cannot find it under that name, and it was only after I browsed through the JNDI tree name that I found out that it is available under the name SimpleService # ds / base / ejb / SimpleService. Help me understand what's going on? How to set up ejb bean so that it is available in ejb / SimpleService,as described in the official weblogic manual? Or maybe this is the correct JNDI name for the EJB bean?
My classes and configs:
ds.base.ejb.SimpleServiceBean:
@Stateless(mappedName = "ServiceBean")
@TransactionAttribute(NEVER)
@ExcludeDefaultInterceptors
@Remote(SimpleService.class)
public class SimpleServiceBean implements SimpleService {
...
}
WebLogic-EJB-jar.xml
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>ServiceBean</ejb-name>
<jndi-name>ejb/ServiceBean</jndi-name>
<enable-call-by-reference>True</enable-call-by-reference>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
application.xml:
<application>
<display-name>web-app-ear</display-name>
<module>
<ejb>app-ejb-1.0-SNAPSHOT.jar</ejb>
</module>
</application>
Then try doing it from standalone:
InitialContext context = new InitialContext(env);
SimpleService simpleService = (SimpleService)
context.lookup("SimpleService#ds/base/ejb/SimpleService");
assert simpleService != null
source to share
there is a good FaQ about the global JNDI portal name on glassfish.org http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#SessionBeanGlobalJNDINameAssignment Your best bet is not to assign the jndi name, but rely on those defined since EE 5 (for example , SimpleService # ds / base / ejb / SimpleService)
If you add the jndi-name configuration to your weblogic-ejb-jar.xml, you can make it available as an ejb / ServiceBean, but you must also define its old-school style in ejb-jar.xml. More details about weblogic-ejb-jar.xml can be found http://docs.oracle.com/cd/E23943_01/web.1111/e13719/ejb_jar_ref.htm
There is also a good overview of dd in the orcl docs. http://docs.oracle.com/cd/E23943_01/web.1111/e13719/understanding.htm#EJBPG129
Assuming you are running server version 10.3.x ...
source to share
Use this.
@Stateless(mappedName="UserFacade")
public class UserFacadeImpl {
//......
}
Properties p=new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7001");
InitialContext ctx=new InitialContext(p);
userFacade=(UserFacade)ctx.lookup("UserFacade#com.webservices.facade.UserFacade");
hope this helps.