我有一种情况,我在服务器上有一个有效的DataSource文件(下面转载),用于连接本地数据库工作正常。我还有许多其他机器具有完全相同的凭证,除了它们的IP地址不同(我也有)。我想在我的localhost DataSource对象中读取并使用不同的ipaddress更新连接URL。我该怎么做呢?我正在使用JBoss 4.2.3进行部署(我无法更改)。
这是我想要创建的方法
/**
* This gets a DataSource for a specified IP address using pacsDS as a template.
* @param ipaddress
* @return
*/
public static DataSource getDataSource(Context context, String ipaddress) throws NamingException {
DataSource ds = (DataSource)context.lookup("java:/pacsDS");
// Update ds to make use of supplied ipaddress
// ...
return ds;
}
这是数据源xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: pacs-postgres-ds.xml 5174 2007-09-26 21:05:41Z gunterze $ -->
<!-- ==================================================================== -->
<!-- Datasource config for Postgres -->
<!-- ==================================================================== -->
<datasources>
<local-tx-datasource>
<jndi-name>pacsDS</jndi-name>
<connection-url>jdbc:postgresql://localhost/pacsdb</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>postgres</user-name>
<password></password>
<!-- sql to call when connection is created. Can be anything, select 1 is valid for PostgreSQL
<new-connection-sql>select 1</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool. Can be anything, select 1 is valid for PostgreSQL
<check-valid-connection-sql>select 1</check-valid-connection-sql>
-->
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>PostgreSQL 7.2</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
答案 0 :(得分:0)
您可以参数化JBoss配置文件。
请参阅https://community.jboss.org/wiki/SystemPropertiesInConfigFiles?_sscc=t