Payara 5 web.xml中PGSimpleDataSource的自定义属性

问题描述 投票:0回答:1

我想使用PostgresQL作为数据库在Payara 5中配置数据源。这是我来自web.xml的代码:

<data-source>
    <name>java:global/my_ds</name>
    <class-name>org.postgresql.ds.PGSimpleDataSource</class-name>
    <server-name>postgres.host.test</server-name>
    <port-number>0</port-number>
    <database-name>mydb</database-name>
    <user>user</user>
    <password>pwd</password>
</data-source>

这很好。但是,我需要在数据源上设置当前模式。 PGSimpleDataSource上有一个方法可以做到这一点,所以我可以通过编程的方式做到这一点。但是,我想配置当前架构以及其他选项。为此,我尝试了:

  1. 将另一个称为<current-schema>my-schema</current-schema>的子标签添加到<data-source>标签。我的IDE抱怨不允许使用此附加标签。
  2. 将名称为current-schemacurrentSchema的属性添加到<data-source>标签。这是允许的,但没有效果。

所以,现在我正在寻找实际起作用的方式。

java postgresql jdbc configuration payara
1个回答
0
投票

正如How can I configure JPA for a postgres database schema?所建议的解决方案实际上是像这样配置属性:

<data-source>
    <name>java:global/my_ds</name>
    <class-name>org.postgresql.ds.PGSimpleDataSource</class-name>
    <server-name>postgres.host.test</server-name>
    <port-number>0</port-number>
    <database-name>mydb</database-name>
    <user>user</user>
    <password>pwd</password>

    <!-- This is the correct property -->
    <property>
        <name>currentSchema</name>
        <value>my-schema</value>
    </property>

</data-source>
© www.soinside.com 2019 - 2024. All rights reserved.