以编程方式为JBoss 4.2.x创建数据源 [英] Programaticly create datasource for JBoss 4.2.x

查看:83
本文介绍了以编程方式为JBoss 4.2.x创建数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在jboss中以编程方式创建数据源并且仍然有一个有效的jndi条目供实体管理器使用?

Would it be possible to programmaticly create a data source in jboss and still have a valid jndi entry for the entity manager to use?

创建数据源是在哪里我迷路了,我希望我可以使用在stat-up上运行的MBean来处理这个问题。

Creating the data source is where I am lost, I hope I can use a MBean that runs on stat-up to handle this.

这不是我首选的方法,但我正在工作的应用程序on有一个托管在另一台服务器上的全局配置文件我想用于配置。

This would not be my preferred method, but the application I am working on has a global configuration file hosted on another server I am suppose to use for configuration.

更新:在这个例子中,我需要以编程方式创建数据源或更改jdbc一个现有数据源的URL。我不知道数据库服务器的URL直到运行时。

update: In this instance I need to create a data source programticly or change the jdbc url of an exsiting datasource. I don't know the DB server url until runtime.

推荐答案

而不是在JBoss的内容中四处寻找这个,我建议使用第三方连接池实用程序,例如 Apache Commons DBCP 。有关如何以编程方式在JNDI上注册DBCP数据源的说明此处

Rather than poking around in the guts of JBoss in order to do this, I suggest using a 3rd-party connection pool utility, such as Apache Commons DBCP. There are instructions on how to programmatically register a DBCP datasource on JNDI here.

示例代码的前两行应该是不必要的,只需创建默认的 InitialContext 然后重新绑定所描述的数据源引用。

The first two lines of the sample code should be unnecessary, just create the default InitialContext and then rebind the datasource reference into it as described.

这篇关于以编程方式为JBoss 4.2.x创建数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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