๐Ÿ”ด The Error You're Seeing

Confirm this matches your console output. If it does, you're in the right place.

ERROR LOG2026-02-20 14:22:18.300 ERROR 8842 --- [ main] o.s.boot.SpringApplication : Application run failed java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: java.lang.IllegalStateException: No DataSource class found for type: com.zaxxer.hikari.HikariDataSource Caused by: java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariDataSource

โšก Quick Fix Works 80% of the time

Add spring-boot-starter-jdbc or spring-boot-starter-data-jpa to your pom.xml.

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency>

๐Ÿง  Why this Happens

Tap to expand the deep technical explanation

Spring Boot defaults to using HikariCP for database connection pooling. When it tried to configure the DataSource, the JVM tried to load the `HikariDataSource` class, but couldn't find it. This means `HikariCP.jar` is missing from your classpath, or it was accidentally excluded.

The HITEC City Parking Spot Analogy:

It's like trying to drive a car, but the engine (HikariCP) was never installed at the factory. You have the keys and the steering wheel, but no power to move.

๐Ÿ” How to Reproduce Confirm this is your error

Create a Spring Boot app. Add a `spring.datasource.url` to properties. Do NOT add `spring-boot-starter-jdbc` or `spring-boot-starter-data-jpa`. Run the app.

๐Ÿ› ๏ธ Solutions (5 Ways to Fix)

Solution 1โœ“ Most common cause

Add the JDBC starter dependency

๐Ÿ‘‰ Use this if you are doing manual JDBC or Spring Data JPA.

The `spring-boot-starter-jdbc` and `spring-boot-starter-data-jpa` starters automatically include HikariCP.

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
Solution 2

Manually add HikariCP dependency

๐Ÿ‘‰ Use this if you only want the pool without the full Spring Data JPA overhead.

Explicitly add the Hikari jar to your pom.xml.

<dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>5.1.0</version> </dependency>
Solution 3

Fix Maven Shade / Fat Jar exclusions

๐Ÿ‘‰ Use this if the dependency is in your pom.xml, but missing at runtime.

If you are building a custom fat-jar, your `maven-shade-plugin` might be excluding HikariCP. Ensure it is included in the final artifact.

<!-- Check shade plugin config for unwanted exclusions -->
Solution 4

Switch to a different connection pool

๐Ÿ‘‰ Use this if you absolutely must use Tomcat JDBC pool.

Tell Spring Boot to stop looking for Hikari and use Tomcat's pool instead.

# application.properties spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
Solution 5

Exclude DataSource Auto-Configuration

๐Ÿ‘‰ Use this if you are not using a database at all.

If the error is happening because a property triggered auto-config but you don't need a DB, turn it off.

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

๐Ÿ“‹ Version Notes

Spring Boot 2.x

HikariCP is the default pool.

Spring Boot 3.x

HikariCP is the default pool.

๐Ÿ›ก๏ธ How to Prevent This Next Time

Always use Spring Initializr to generate your project. Checking the 'Spring Data JPA' or 'JDBC API' boxes guarantees the correct pooling dependencies are added.

Course Search
Search across all chapters & stages
๐Ÿ“–

Search the course

Type any topic โ€” branching, stash, rebase, hooks โ€” and jump straight to that chapter.

merge branchesgit stashundo commitrebase