【发布时间】:2017-01-25 05:35:48
【问题描述】:
我正在尝试在我的 Web 应用程序中将 HikariCP 与 PostgreSQL 集成,我正在使用 postgresql 驱动程序和这个 DataSource 类:org.postgresql.ds.PGSimpleDataSource 和我的休眠配置文件是这样的:
<property name ="hibernate.connection.provider_class"> com.zaxxer.hikari.hibernate.HikariConnectionProvider</property>
<property name ="hibernate.hikari.dataSourceClassName"> org.postgresql.ds.PGSimpleDataSource</property>
<property name ="hibernate.hikari.dataSource.url">jdbc:postgresql:// localhost:5432/database</property>
<property name ="hibernate.hikari.dataSource.user">user</property>
<property name ="hibernate.hikari.dataSource.password">passwd</property>
<property name ="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
当我运行我的应用程序时,我遇到了这个异常:
org.hibernate.HibernateException: java.lang.RuntimeException: 目标类 org.postgresql.ds.PGSimpleDataSource 上不存在属性 url `
【问题讨论】:
-
您为什么要通过
PGSimpleDataSource使用数据源? Hikari 不应该负责提供数据源吗? -
使用 Hibernate 提供的 org.hibernate.hikaricp.internal.HikariCPConnectionProvider,HikariCP 中的那个已经被弃用了。此外,使用 PostgreSQL 数据源,您不需要 URL,只需设置数据库名称即可。
标签: java postgresql hibernate jdbc hikaricp