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

Custom Property for PGSimpleDataSource in Payara 5 web.xml

我想使用 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> 标签。这是允许的,但没有效果。

所以,现在我正在寻找实际可行的方法。

正如 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>