以编程方式为 JBoss 4.2.x 创建数据源 [英] Programaticly create datasource for 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.
这不是我的首选方法,但我正在开发的应用程序在另一台服务器上托管了一个全局配置文件,我想将其用于配置.
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.
推荐答案
我建议使用 3rd-party 连接池实用程序,例如 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
,然后按照描述将数据源引用rebind
.
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屋!