Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing the Environment Values(Ejb-jar.xml)  RSS feed

 
perry arora
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends.,


I am attaching the copy of my ejb-jar.xml, and the code also whic i am using to , fetch the value of an <b>Environment variable named interestrate</b>


<session>
<env-entry>
<description>Reflect the present interest rate</description>
<env-entry-name>interestrate</env-entry-name>
<env-entry-type>java.lang.Float</env-entry-type>
<env-entry-value>9.0</env-entry-value>
</env-entry>

</session>


Code used to acess the variable

Context initialcontext = new InitialContext();
(Float)initialcontext.lookup("java:comp/env/interestrate")

But i am getting a Java.NameNotFoundException

I am able to access the local session bean using the ejb-ref under the context java:comp/env/ejb/local .

But when i am trying to use the above code for accessing the environment variable , in a method of the stateless session bean i am not able to


Need you help

Thxs

Perry
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks correct to me. I would just go back and check that case and spelling match exactly between the deployment descriptor and the Java code.
 
Lalita Sattavat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
since you are trying to lookup for the value defined in the session bean, try using the entitycontext rather than the initial context. check now if u get that value
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lalita Sattavat:
since you are trying to lookup for the value defined in the session bean, try using the entitycontext rather than the initial context. check now if u get that value

First of all, since it is a SessionBean then it would be the SessionContext. Secondly, using SessionContext.getEnvironment() to look up environment variables is the old EJB 1.0/1.1 way of doing things which is now deprecated. The proper way of looking up environment variables is exactly how Perry is doing it by using JNDI.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!