轻松启动独立JNDI服务器(并注册一些资源) [英] Easy way to start a standalone JNDI server (and register some resources)
问题描述
出于测试目的,我正在寻找一种简单的方法来启动独立的 JNDI服务器,并将我的javax.sql.DataSource绑定到java:/ comp / env / jdbc / mydatasource
以编程方式。
For testing purposes, I'm looking for a simple way to start a standalone JNDI server, and bind my javax.sql.DataSource to "java:/comp/env/jdbc/mydatasource"
programmatically.
服务器应将自身绑定到某个URL,例如:java.naming.provider.url = jnp:// localhost:1099(不一定是JNP),这样我就可以从另一个进程查找我的数据源。我不关心我必须使用哪个JNDI服务器实现(但我不想启动一个成熟的JavaEE服务器)。
The server should bind itself to some URL, for example: "java.naming.provider.url=jnp://localhost:1099" (doesn't have to be JNP), so that I can look up my datasource from another process. I don't care about which JNDI server implementation I'll have to use (but I don't want to start a full-blown JavaEE server).
这应该很容易,但令我惊讶的是,我找不到任何(工作)教程。
This should be so easy, but to my surprise, I couldn't find any (working) tutorial.
推荐答案
JDK包含一个< a href =http://download.oracle.com/javase/6/docs/technotes/guides/jndi/jndi-rmi.html\"rel =nofollow> RMI注册管理机构的JNDI提供商。这意味着您可以将RMI注册表用作JNDI服务器。所以,只需启动 rmiregistry ,设置 java.naming.factory.initial 到 com.sun.jndi.rmi.registry.RegistryContextFactory ,你就走了。
The JDK contains a JNDI provider for the RMI registry. That means you can use the RMI registry as a JNDI server. So, just start rmiregistry, set java.naming.factory.initial to com.sun.jndi.rmi.registry.RegistryContextFactory, and you're away.
RMI注册表有一个扁平的命名空间,所以你将无法绑定到java:/ comp / env / jdbc / mydatasource,但你将能够绑定到的东西,所以它将接受java:/ comp / env / jdbc / mydatasource,但是将它视为单个组件名称(谢谢,@ EJP)。
The RMI registry has a flat namespace, so you won't be able to bind to java:/comp/env/jdbc/mydatasource, but you will be able to bind to something so it will accept java:/comp/env/jdbc/mydatasource, but will treat it as a single-component name (thanks, @EJP).
我写了一个小应用程序来演示如何执行此操作: https://bitbucket.org/twic/jndiserver/src
I've written a small application to demonstrate how to do this: https://bitbucket.org/twic/jndiserver/src
我仍然不知道JNP服务器应该如何工作。
I still have no idea how the JNP server is supposed to work.
这篇关于轻松启动独立JNDI服务器(并注册一些资源)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!