๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-02-14 16:10:40.100 ERROR 8842 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
java.net.ConnectException: Connection refused: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at com.zaxxer.hikari.pool.HikariPool.newConnection(HikariPool.java:345)โก Quick Fix Works 80% of the time
Ensure your database server (MySQL/Postgres) is running and the port in application.properties matches.
# Check if DB is running on default port
# application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb๐ ๏ธ Solutions (3 Ways to Fix)
Start your database server
๐ Use this if you forgot to start MySQL/Postgres locally or your Docker container crashed.
Connection refused means the OS rejected the connection because nothing is listening on that port. Start the DB service.
# Start Postgres via Docker
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=secret postgres:15
# Or start local MySQL service
sudo systemctl start mysqlCheck the port number in the URL
๐ Use this if the DB is running, but Spring is pointing to the wrong port.
Ensure the port in your spring.datasource.url matches the port your database is actually listening on. MySQL defaults to 3306, Postgres to 5432.
# Wrong port (e.g., pointing to Postgres on MySQL port)
# spring.datasource.url=jdbc:postgresql://localhost:3306/mydb
# Correct port
spring.datasource.url=jdbc:postgresql://localhost:5432/mydbUse 'localhost' instead of '127.0.0.1' (or vice versa)
๐ Use this if IPv6 vs IPv4 resolution is causing issues on Windows/Mac.
Sometimes 'localhost' resolves to IPv6 (::1) but the DB only listens on IPv4 (127.0.0.1). Changing the URL can force the correct protocol.
# Try changing localhost to 127.0.0.1
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mydb๐ Version Notes
Uses HikariCP as default connection pool. Throws HikariPool initialization error.
Identical behavior, but HikariCP logs are slightly more detailed.
๐ง Why this Happens
Tap to expand the deep technical explanation
Spring Boot's connection pool (HikariCP) attempted to open a TCP socket to the IP and port specified in your spring.datasource.url. The operating system at that address actively refused the connection because no database server was listening there.
The HITEC City Parking Spot Analogy:
It is like calling a friend whose phone is switched off. The network works, but because their phone isn't on, the call is instantly rejected.
๐ก๏ธ How to Prevent This Next Time
Use Docker Compose to manage your database alongside your Spring Boot app so they start and stop together.