aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB environment question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB environment question." Watch "EJB environment question." New topic
Author

EJB environment question.

Claudio Gualberto
Ranch Hand

Joined: Oct 13, 2002
Posts: 47
Hi all,
I have an ejb-jar with several EJB ( Session, Entity BMP, etc ). I want to pass to all EJB inside this JAR a parameter as an String ( i.e , the data source�s JNDI name they must to connect to)
and i know that a must use the JNDI naming context java:comp/env to access enterprise bean's environment.
The questions are :
* When i lookup for "java:comp/env" what Java type will be returned ?
* How to get the environment entries ?
* Once on the EJB descriptor, the env-entry
is related to some EJB. But how can i define only one env-entry and it be acessed by all EJB�s on the application.
If anyone knows an document with this answers, please tell me where to find.
Any help will be apreciated.
Claudio Gualberto.
SCJP 1.4
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
When i lookup for "java:comp/env" what Java type will be returned ?

javax.naming.Context
How to get the environment entries ?

Context envContext = <jndi lookup for java:comp/env>
String property = (String) envContext.lookup("MyEnvEntry");
Once on the EJB descriptor, the env-entry
is related to some EJB. But how can i define only one env-entry and it be acessed by all EJB�s on the application.

I am not aware of a way to do this (which by far doesn't mean that there wouldn't be a way)...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Claudio Gualberto
Ranch Hand

Joined: Oct 13, 2002
Posts: 47
Thanks for your help, the last question is really hard to find the answer.
Maybe there is another way to do what i want.
Let�s see :
I have some DataSources that maps the same data base schema, but to diferent data base instances.
I would like easily change the DataSource name by changing something on the deployment descriptor
or other place, thus my beans will get connections from several sources with no change on the code.
Do you have some idea ?
Claudio Gualberto.
SCJP 1.4
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
I have some DataSources that maps the same data base schema, but to diferent data base instances. I would like easily change the DataSource name by changing something on the deployment descriptor or other place, thus my beans will get connections from several sources with no change on the code.

The thing you need to change is the vendor-specific deployment descriptor. That's where you actually point the datasource into a database instance (and define usernames, passwords, etc). You need to consult your appserver's documentation on this one.
 
 
subject: EJB environment question.