-
1. Re: EJB lookup without java:comp/env/
jaysensharma Jul 25, 2012 11:58 AM (in response to jmfaerman)Hi Julio,
In "Standalone-full.xml" you can map the JNDI name to "java:comp/env/ejb/MyBean" as following:
<subsystem xmlns="urn:jboss:domain:naming:1.2">
<bindings>
<lookup name="java:global/ejb/MyBean" lookup="java:global/EJB2Demo/MySessionBean!ejb2.demo.InterestCalculatorHome"/>
</bindings>
<remote-naming/>
</subsystem>
In "web.xml" of your applicationyou can use <ejb-ref> as following:
<ejb-ref>
<ejb-ref-name>ejb/MyBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>ejb2.demo.InterestCalculatorHome</home>
<remote>ejb2.demo.InterestCalculatorRemote</remote>
</ejb-ref>
And your JSP lookup code will look like following:
<%@ page import="java.util.*,javax.ejb.*,javax.naming.*,javax.rmi.*" %>
<%
String jndiName = "java:comp/env/ejb/MyBean";
Context ic = new InitialContext();
System.out.println("\n\t Inside index.jsp About to look up jndi name " + jndiName);
Object obj = ic.lookup(jndiName);
System.out.println("\n\tlookup returned " + obj);
ejb2.demo.InterestCalculatorHome home=(ejb2.demo.InterestCalculatorHome)obj;
ejb2.demo.InterestCalculatorRemote remote=(ejb2.demo.InterestCalculatorRemote)home.create();
System.out.println("\n\tremote.calculateInterest(10.0,20f,30)= "+remote.calculateInterest(10.0,20f,30));
System.out.println("\n\tremote.calculateInterest(10.0,20f,30)= "+remote.calculateInterest(10.0,20f,30));
%>
-
2. Re: EJB lookup without java:comp/env/
sfcoy Jul 25, 2012 12:07 PM (in response to jmfaerman)Julio Faerman wrote:
... all JNDI lookups (EJB 2) are not prefixed by java:comp/env/
This means your application was never portable. If you want to run in JBoss AS 7.x I don't think you will have any choice. You must change the lookup names in your code.
-
3. Re: EJB lookup without java:comp/env/
jaysensharma Jul 25, 2012 12:31 PM (in response to sfcoy)EJB 2.0 added local interfaces that do not use RMI call by value semantics. These interfaces use a call by reference semantic and therefore do not incur any RMI serialization overhead. An EJB local reference is a link in an application component naming environment that points to a deployed EJB local home interface. The name used by the application component is a logical link that isolates the component from the actual name of the EJB local home in the deployment environment. The J2EE specification recommends that all references to enterprise beans be organized in the java:comp/env/ejb context of the application component's environment.
An <ejb-ref-name> element that specifies the name of the reference relative to the java:comp/env context. To place the reference under the recommended java:comp/env/ejb context, use an ejb/link-name form for the ejb-ref-name value.
-
4. Re: EJB lookup without java:comp/env/
jmfaerman Jul 25, 2012 1:02 PM (in response to sfcoy)I wish it was my code to change
I know it is not standard and portable, but unfortunately this clients current AS (OAS) and other prospects (Weblogic) seems to handle it.