• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Accessing the Environment Values(Ejb-jar.xml)

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A wop bop a lu bop a womp bam boom! Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic