如何在运行时使用 Open Liberty 切换数据库?
How to switch database with Open Liberty on runtime?
我正在尝试通过设置我在 server.xml.
中使用的变量,使用 maven-liberty-plugin
在 Open Liberty 中切换数据库主机
在我的 pom.xml 中,我有以下 属性:
<liberty.var.postgres.host>database</liberty.var.postgres.host>
在我的 server.xml 我有这个(摘录):
<variable name="postgres.host" defaultValue="database"/>
<dataSource id="todoListDS"
jndiName="jdbc/TodoListDS"
type="javax.sql.ConnectionPoolDataSource">
<jdbcDriver id="postgresql-driver"
javax.sql.XADataSource="org.postgresql.xa.PGXADataSource"
javax.sql.DataSource="org.postgresql.ds.PGDataSource"
javax.sql.ConnectionPoolDataSource="org.postgresql.ds.PGConnectionPoolDataSource"
libraryRef="postgresql-library"/>
<properties.postgresql serverName="${postgres.host}"
portNumber="${postgres.port}"
databaseName="${postgres.database}"
user="${postgres.user}"
password="${postgres.password}"/>
</dataSource>
然后我 运行 我的服务器通过: mvn -Dliberty.var.postgres.host=localhost clean package liberty:run
但是连接似乎失败了。我对 https 端口进行了同样的尝试,效果很好。只是数据库主机似乎不起作用。
当我将 pom.xml 中的 liberty.var.postgres.host
更改为 localhost
时,它会起作用。
如何在这里切换数据库主机?
查看问题的评论以获得答案。
我正在尝试通过设置我在 server.xml.
中使用的变量,使用maven-liberty-plugin
在 Open Liberty 中切换数据库主机
在我的 pom.xml 中,我有以下 属性:
<liberty.var.postgres.host>database</liberty.var.postgres.host>
在我的 server.xml 我有这个(摘录):
<variable name="postgres.host" defaultValue="database"/>
<dataSource id="todoListDS"
jndiName="jdbc/TodoListDS"
type="javax.sql.ConnectionPoolDataSource">
<jdbcDriver id="postgresql-driver"
javax.sql.XADataSource="org.postgresql.xa.PGXADataSource"
javax.sql.DataSource="org.postgresql.ds.PGDataSource"
javax.sql.ConnectionPoolDataSource="org.postgresql.ds.PGConnectionPoolDataSource"
libraryRef="postgresql-library"/>
<properties.postgresql serverName="${postgres.host}"
portNumber="${postgres.port}"
databaseName="${postgres.database}"
user="${postgres.user}"
password="${postgres.password}"/>
</dataSource>
然后我 运行 我的服务器通过: mvn -Dliberty.var.postgres.host=localhost clean package liberty:run
但是连接似乎失败了。我对 https 端口进行了同样的尝试,效果很好。只是数据库主机似乎不起作用。
当我将 pom.xml 中的 liberty.var.postgres.host
更改为 localhost
时,它会起作用。
如何在这里切换数据库主机?
查看问题的评论以获得答案。