yegor256
yegor256

Reputation: 105073

Simple JNDI ContextFactory?

My WAR application is deployed to Amazon Elastic Beanstalk. They don't support JNDI, but I need it for JPA and unit tests. What JNDI context factory I can use as a workaround? I need a simple open source solution, that would allow me to configure entire factory through jndi.properties. I tried GuiceyFruit, but looks like it doesn't allow data source configuration inside one file. Any suggestions?

ps. OpenEJB will work, but it's an overkill for such a simple task

Upvotes: 1

Views: 5254

Answers (1)

Holger Thurow
Holger Thurow

Reputation: 824

Try Simple-JNDI. It gives you an in-memory implementation of a JNDI Service and allows you to populate the JNDI environment with objects defined in property files. There is also support for loading datasources or connection pools configured in a file.

To get a connection pool you have to create a file like this:

type=javax.sql.DataSource
driver=com.sybase.jdbc3.jdbc.SybDriver
pool=myDataSource
url=jdbc:sybase:Tds:servername:5000
user=user
password=password 

In your application you can access the pool via

Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("path/to/your/connectionPool");

You can find more about it at https://github.com/h-thurow/Simple-JNDI.

Upvotes: 3

Related Questions