Tip: take into account jndi.properties with EJBContainer


EJBContainer doesn’t have to take into account jndi.properties file. For those who were using new InitialContext() to start their (OpenEJB) container for tests it can be quite strange.

An easy way to solve it is to read manually the properties file and give the properties to the createEJBContainer method. Doing it your jndi.properties will be used but the java one (${java.home/lib/jndi.properties) will be ignored where it was taken into account before. Same with system properties…

So what to do?

Accepting to get a dependency on sun classes (quite acceptable, at least for testing) you can use the com.sun.naming.internal.ResourceManager class and its getInitialEnvironment  method.

Simply replace

 EJBContainer.createEJBContainer()
 

by

 EJBContainer.createEJBContainer(ResourceManager.getInitialEnvironment(new Properties()));
 

And you will inherit from all the InitialContext behavior regarding jndi.properties 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s