我正在尝试找出如何使用pgproperty属性来配置hikari数据源。
这很好:
final String jdbcUrl = String.format(
"jdbc:postgresql://%s:%s/%s?ApplicationName=%s",
configuration.getDatabaseHost(),
configuration.getDatabasePort(),
configuration.getDatabaseName(),
configuration.getDatabaseAppName());
hikariDataSource.setJdbcUrl(jdbcUrl);
hikariDataSource.setUsername(configuration.getDatabaseUsername());
hikariDataSource.setPassword(configuration.getDatabasePassword());
hikariDataSource.setMaximumPoolSize(configuration.getDatabaseMaximumPoolSize());
但是我希望能够使用pgproperty来避免像上面那样手工构建jdbc url。当我尝试这个:
hikariDataSource.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
hikariDataSource.addDataSourceProperty(PGProperty.PG_HOST.getName(), configuration.getDatabaseHost());
hikariDataSource.addDataSourceProperty(PGProperty.PG_PORT.getName(), configuration.getDatabasePort());
hikariDataSource.addDataSourceProperty(PGProperty.PG_DBNAME.getName(), configuration.getDatabaseName());
hikariDataSource.addDataSourceProperty(PGProperty.APPLICATION_NAME.getName(), configuration.getDatabaseAppName());
hikariDataSource.addDataSourceProperty(PGProperty.USER.getName(), configuration.getDatabaseUsername());
hikariDataSource.addDataSourceProperty(PGProperty.PASSWORD.getName(), configuration.getDatabasePassword());
我得到这个错误:
Property PGHOST does not exist on target class org.postgresql.ds.PGSimpleDataSource
https://jdbc.postgresql.org/documentation/publicapi/org/postgresql/pgproperty.html
1条答案
按热度按时间jdg4fx2g1#