What's the easiest way to provide an EJB data like a JDBC driver, a database's URL, and a database's username and password without hard coding those parameters into the EJB? I think it has something to do with the <resource-ref> tag, but I am having a little trouble figuring this one out. I'm familiar with doing this in the Web Container with web.xml, but not with EJBs. Anyhow, if someone could help me out with an example, I'd really appreciate it. Thanks!
I guess I need to further specify what I'm looking for. I used the JDBC parameters as an example, but I'm really just looking for a way to pass all sorts of configuration parameters to an EJB, not just JDBC specifics. Even if I create a Connection Pool and a DataSource, I'm still hard coding the JNDI context name into the code, and I'd like to avoid that. Is there something equivalent to config.getInitParam("paramName") in a servlet? I guess I could create a set method for the parameters, but then I'm reliant upon clients executing that set method prior to running any methods that might require the parameters.
I think you should be clear with hard coding. For a given piece of code which is dependent on some external parameters, and if these external parameters is present in your code then its called hard coding.
Regarding EJB , the container takes care of maintaining a connection pool. It only needs a JNDI name. Specifying a JNDI name in your code is not called hard coding. If tommorrow u change your database or driver u should not compile ur code.
Is there something equivalent to config.getInitParam("paramName") in a servlet
Above you are mentioning "paramName" , is it not hard coding w.r.t to your understanding.
OK, with paramName, that can be configured externally in web.xml. Yes the paramName is hard coded, but its value can be changed from the web.xml file thus preventing code changes. You recommend using JNDI, which is great, but doesn't solve my problem. Here's why:
So in the above example I have three things that I consider "hard coded". Number one is the url to the JNDI tree, number two is the INITIAL_CONTEXT_FACTORY value of "weblogic.jndi.WLInitialContextFactory", and number three is the DataSource with the value of "jhuDataSource". I'm new to EJB, but they are supposed to be distributable and configurable right?. I thought for sure there would be a way to supply these pieces of information to my EJB without hard coding, but now I'm not sure. In a servlet or JSP you use the web.xml file to supply parameters like these. Can you do this with EJB?