Configuring and looking up a simple String via JNDI in WebSphere

Udo Held picture Udo Held · Nov 24, 2011 · Viewed 26.1k times · Source

For the configuration of our applications we want to place some of the configuration in the application server.

We are currently using the WebSphere JNDI facility for looking up urls and datasources.

In addition we want to place simple Strings in the application server. We don't want to use the WebSphere "Enviroment variables".

Can the "Resource Environment" be used for such a purpose? If so, how can it be used?

We'd like to get the Strings with:

InitialContext ctx = new InitalContext();
String myString = (String)ctx.lookup("jndi/string/myString");

Are there any more simple alternatives?

We are using WebSphere Application Server 7.

Answer

DagR picture DagR · Nov 24, 2011

Take a look at the article Using resource environment providers in WebSphere Application Server

It's written for WebSphere 5 or 6 but the idea should work for version 7 too. Basically you create a custom resource environment provider, which returns objects of your own type via a factory. The factory implements javax.naming.spi.ObjectFactory and gets its input from Websphere.

In my opinion this is a nice solution if you have a few configuration parameters but it can quickly become hard to maintain as the number of parameters grows.