简体   繁体   English

Wildfly 中的动态数据源配置

[英]Dynamic datasource config in wildfly

I have a wildfly 10 (Java + Spring) project.我有一个wildfly 10(Java + Spring)项目。 I have a requirement to dynamically inject the datasource (mysql) config details to wildfly.我需要将数据源(mysql)配置详细信息动态注入wildfly。 But since wildfly depends on the standalone xml file at startup, and needs it before even the java beans are created, the only way I've found so far is to inject is by setting env vars (by running some other program/script to fetch the configs before wildfly starts).但是由于wildfly在启动时依赖于独立的xml文件,并且在创建java bean之前需要它,所以到目前为止我发现的唯一方法是注入是通过设置env vars(通过运行一些其他程序/脚本来获取Wildfly 启动前的配置)。 Is there any other better option?还有其他更好的选择吗?
Is it possible to do this through the same java application itself, ignoring the xml and set the right config?是否可以通过相同的 java 应用程序本身来执行此操作,而忽略 xml 并设置正确的配置? If yes, how?如果是,如何?

DataSource object via JNDI通过 JNDI 的DataSource object

Externalize your JDBC connection details by using JNDI to access a naming/directory server to obtain an object implementing the DataSource interface.通过使用JNDI访问命名/目录服务器以获取实现DataSource接口的 object,将您的 JDBC 连接详细信息外部化。

With a DataSource object in hand, call getConnection to obtain a Connection .使用DataSource object ,调用getConnection获取Connection

See tutorial by Oracle, Connecting with DataSource Objects .请参阅 Oracle 的教程, 连接数据源对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM