views:

28

answers:

2

Hi, What's the norm / best practices for saving/retrieving application settings in a EJB3 app? I'm using maven as a build tool, and I have a multi module project.

I was thinking of putting some properties file on some common module that would be available application-wise as a jar but I'm not sure if an EJB is more suited for this.


Edit: The application properties should be configurable per environment. My main issue is how to expose the properties to the rest of the container, my secondary issue is how to save them in a environment-dependent way

A: 

If the settings are to be changed on a regular basis then locking them in a properties file within a jar is going to make life difficult.

If the settings pertain to resources such as database or JMS connection urls, then those are best defined to the container and accessed via a JNDI lookup.

You could use context-param or servlet init-params in the web.xml, there must be something similar in the application.xml - I haven't looked at them in a while.

You could define them in an LDAP, and then extend the JNDI tree to include that branch.

Although I would probably just use a properties file located in a directory on the classpath outside of the ear/war/jar deployment structure.

crowne
I used a combination of two files, one on the classpath for environment-specific properties and another on a jar for things like revision number, build date, etc.
Miguel Ping
A: 

What's the norm / best practices for saving/retrieving application settings in a EJB3 app?

EJB3 app is very vague... But I would say that things like an endpoint URLs for external services would typically go in JNDI as environment entries (that you could then inject with the @Resource annotation) if you want to maximize portability.

Pascal Thivent