I am facing this error from kubernetes cluster. Though it works perfectly from my local server. Here is my application.yml of SpringBoot App
datasource:
dataSourceClassName: org.postgresql.ds.PGPoolingDataSource
url: jdbc:postgresql://${POSTGRES_HOST}:5432/test_db
databaseName: test_db
poolName: SpringBootHikariCP
username: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}
testWhileIdle: true
validationQuery: SELECT 1
jpa:
database-platform: org.hibernate.dialect.PostgreSQL82Dialect
openInView: false
show_sql: true
generate-ddl: true
hibernate:
ddl-auto: update
naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
use-new-id-generator-mappings: true
properties:
hibernate.cache.use_second_levelt_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.hbm2ddl.auto: validate
Here is my Hikari configuration.
HikariConfig config = new HikariConfig();
config.setDataSourceClassName(dataSourceClassName);
config.addDataSourceProperty("url", url);
config.addDataSourceProperty("user", user);
config.addDataSourceProperty("password", password);
return new HikariDataSource(config);
I have checked DB connectivity of kubernetes without Hikari and it works perfectly. So there is no issue with connectivity. Please help me regarding the issue. I am stuck with this for couple of days. Thank you
${POSTGRES_HOST}
is expecting a system environment variable that you probably missing in the specific machine, add it for example:
export POSTGRES_HOST="1.1.1.1"
Change the url
to jdbc:postgresql://localhost:5432/test_db
or
jdbc:postgresql://<host ip>:5432/test_db
It looks like the problem with the placeholder ${POSTGRES_HOST}
Try with localhost
datasource:
dataSourceClassName: org.postgresql.ds.PGPoolingDataSource
url: jdbc:postgresql://localhost:5432/test_db;
databaseName: test_db
poolName: SpringBootHikariCP
username: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}
testWhileIdle: true
validationQuery: SELECT 1
Might be you have not set the environment variable ${POSTGRES_HOST}, that also can be a reason.