简体   繁体   English

带有 Postgres 的 Searchpath 不适用于 Spring/DBCP 数据源

[英]Searchpath with Postgres does not work with Spring/DBCP datasource

Postgres extensions are installed in public schema. Postgres 扩展安装在公共模式中。 Set the search path for the app-specific schema on the DBCP datasource the following way:通过以下方式在 DBCP 数据源上设置特定于应用程序的架构的搜索路径:

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" primary="true">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://myhost:myport/${db.gos_app.database}?searchpath=mySchema,public;?ApplicationName=${app.name}"/>
    <property name="connectionProperties" value="currentSchema=mySchema;"/>
    <property name="username" value="user"/>
    <property name="password" value="pw"/>
    <property name="defaultAutoCommit" value="false"/>
    <property name="maxActive" value="6" />
</bean>

But somehow I cannot use extensions installed in this public schema without qualifying them like "public.hstore".但不知何故,如果没有像“public.hstore”那样限定它们,我就不能使用安装在这个公共模式中的扩展。

Found the solution - JDBC driver does not know the searchpath property in the URL.找到解决方案 - JDBC 驱动程序不知道 URL 中的 searchpath 属性。 But this has been nowhere reported :-( Instead currentSchema is given to driver which is then mapped to native Postgres searchpath (thus probably overwriting the default one there with public included). Not intuitive!但这一直没有报道:-(相反, currentSchema 被提供给驱动程序,然后将其映射到本机 Postgres 搜索路径(因此可能用包含 public 的方式覆盖那里的默认路径)。不直观!

So the solution looks like this:所以解决方案如下所示:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" primary="true">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://myhost:myport/${db.gos_app.database}?ApplicationName=${app.name}"/>
<property name="connectionProperties" value="currentSchema=mySchema,public;"/>
<property name="username" value="user"/>
<property name="password" value="pw"/>
<property name="defaultAutoCommit" value="false"/>
<property name="maxActive" value="6" />

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

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