简单的JNDI ContextFactory? [英] Simple JNDI ContextFactory?

查看:124
本文介绍了简单的JNDI ContextFactory?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WAR应用程序已部署到Amazon Elastic Beanstalk。它们不支持JNDI,但我需要它用于JPA和单元测试。我可以使用什么JNDI上下文工厂作为解决方法?我需要一个简单的开源解决方案,这将允许我通过 jndi.properties 配置整个工厂。我尝试过GuiceyFruit,但看起来它不允许在一个文件中配置数据源。有什么建议吗?

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可以工作,但这对于这么简单的任务来说太过分了

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

推荐答案

尝试使用Simple-JNDI。它为您提供了JNDI服务的内存实现,并允许您使用属性文件中定义的对象填充JNDI环境。还支持加载文件中配置的数据源或连接池。

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");

您可以在 https://github.com/h-thurow/Simple-JNDI

这篇关于简单的JNDI ContextFactory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆