Where to store application settings

Y

yzzzzz

Hi,

I have a few settings in my webapp (address of the LDAP server, location
of 2 or 3 files), which are in the source code at the moment. This makes
it difficult to change them (and I have to recompile every time). Where
is the best place to store these kinds of settings? I thought of using a
RessourceBundle, what do you think?

Thanks
 
J

Josh

I usually put a properties file someone in the web application then use a
"startup servlet" that loads it. The startup servlet has an init-param
pointing at the file. Once I've created the properties file, I put it in an
environment object that is shared by everyone.

try {

String propsFile = config.getInitParameter("application.properties");

if (propsFile != null) {
Properties properties = new Properties();
properties.load(context.getResourceAsStream(propsFile));
Environment.initialize(properties);
} else {
throw new Exception("Couldn't find application.properties.");
}

} catch (Exception e) {
logger.error("Couldn't load application properties.", e);
throw new UnavailableException("Couldn't load application
properties.");
}
 
B

Brian Munroe

I place mine in the WEB-INF/web.xml deployment descriptor for the web
application.

For example:

in WEB-INF/web.xml (in between the <webapp> </webapp> tag)

<env-entry>
<env-entry-name>docBase</env-entry-name>
<env-entry-value>doc1</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>

<env-entry>
<env-entry-name>docBaseUser</env-entry-name>
<env-entry-value>munroeb</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>

In the servlet or JavaBean that I need the resources:

Context env = (Context) new InitialContext().lookup("java:comp/env");
String docBase = (String) env.lookup("docBase");
String docBaseUser = (String) env.lookup("docBaseUser");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,194
Latest member
KarriWhitt

Latest Threads

Top