Question

I am going through the example doc for EJB on below URL

http://docs.oracle.com/cd/E11035_01/wls100/ejb30/examples.html#wp1200600

As far as I know in EJB 2.0 we give JNDI name in deployment descriptor in ejb-jar.xml or weblogic-ejb-jar.xml file but in EJB 3.0, I can not find such descriptor where it contains JNDI name.

Can you please suggest where do we provide the JNDI & EJB names so that client can invoke the EJB?

Was it helpful?

Solution

Bindings support in the EJB container has been expanded. The EJB container assigns default JNDI bindings for EJB 3.x business interfaces based on application name, module name, and component name. You do not have to explicitly define JNDI binding names for each of the interfaces or EJB homes within an EJB 3.x module or no-interface views within an EJB 3.1 module.

When defining bindings, you specify Java Naming and Directory Interface (JNDI) names for the referenceable and referenced artifacts in an application. The jndiName values specified for artifacts must be qualified lookup names.

You do not need to manually assign JNDI bindings names for each of the interfaces, EJB homes, or no-interface views on your enterprise beans in EJB 3.x modules. If you do not explicitly assign bindings, the EJB container assigns default bindings.

So, it seems to change the name you will have to configure the specific deployment descriptor for your container.


How to specify a different jndi-name than the default for an EJB in JBoss 4.2.2.GA?


EDITED:

Here more information for weblogic:

In the book "Oracle WebLogic Server" (written by Robert Patrick, Gregory Nyberg, and Philip Aston, with Josh Bregman and Paul Done) Chapter 6: Building Enterprise JavaBeans in WebLogic Server Page 194 " WebLogic Server provides two options for mapping a session bean's remote business interfaces into the global JNDI tree. The mapping can be specified in the weblogic-ejb-jar.xml deployment descriptor or the mappedName element of the @ Stateless or @ Stateful annotations can be used." So there is no default jndi name if you do not use mappedName or weblogic-ejb-jar.xml

Weblogic 10.3.5 & EJB 3 JNDI names

OTHER TIPS

WebLogic 12 (other servers may act differently)

when using the @EJB annotation, container by default assigns the name to the bean

@Singleton
@Startup
public class PoolOracleBean {
/** some code **/
}

and it can be access by the code:

InitialContext initialContext = new InitialContext();
Context context = (Context)initialContext.lookup("java:global/web");
PoolOracleBean pool = (PoolOracleBean)context.lookup("PoolOracleBean");
Connection connection = pool.getConnection();
...

to get a list of all annotated @EJB, in the console:

Environement --> Servers --> "server name" --> View JNDI Tree

there is java:global node with web sub-node

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top