Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

J2EE Application/Bean configuration Best Practices?

What is the best way to manage property sets to apply to EJB, and easily be able to vary them between machines/environments (e.g. DEV, TEST, PROD)? For example, is there a way to configure your EJB properties on the App Server (which guarantees you can vary them by machine/environment).

Specifically:

1) I have a Singleton EJB which needs certain properties set (environment) specific. Is there annotation(s) which are used to tell the EJB Container where to look up those properties and will automatically apply them to the bean?

2) What is the best way to manage different property sets, i.e. dev, test, prod, so that the J2EE app is portable between servers, and you can seamlessly manage the properties specific to each server?

If there are any good documentation links - let me know. I've Googled around and seen nothing directly to the points above.

like image 524
Sam Goldberg Avatar asked Nov 05 '22 06:11

Sam Goldberg


1 Answers

I use a singleton helper class "PropertiesHelper" which has a Properties member and reads from an xml configuration file upon the first property access attempt. The helper encapsulates the entire set of configuration settings and prevents them from being read from disk more than once.

The file location is specified in my java opts and read in by PropertiesHelper using System.getProperty()

As for system properties annotations, I don't believe Java supports this natively, but if you're so inclined you may want to look at some AOP/Dependency Injection frameworks like Google Guice which are better at this "cross-cutting".

like image 112
jpredham Avatar answered Nov 15 '22 11:11

jpredham