Explain the difference between the look up of “java:comp/env/ejb/MyBean” and “ejb
by, 01-02-2012 at 07:27 PM (2636 Views)
The alias or logical reference java:comp/env/ejb/MyBean has always been a recommended approach as the physical JNDI location i.e. ejb/MyBean may not be guaranteed that it (specified in the code) will be present. In case the physical location is changed, code will also be broken down. Your code will not be able to get modified by the deployer. This problem is solved by the logical references which bind the logical names in the application server to the physical name. Declaration will be done of the logical names in deployment descriptors as following (web.xml and/or ejb-jar.xml). In application server specific descriptors they will get mapped to the JNDI physical locations.
For looking up a JDBC resource, either from EJB (ejb-jar.xml) or WEB (web.xml) tier, the deployment descriptor should consist of this entry:
XML Code: This is the code to define JDBC Data Source<resource-ref> <description>The DataSource</description> <res-ref-name>jdbc/MyDataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>