Spring Boot - Cannot determine embedded database driver class for database type NONE
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Spring Boot's ease of use and streamlined setup make it a popular choice for developing Java-based applications. Its ability to automatically configure applications based on the libraries present on the classpath is a significant advantage. However, this auto-configuration feature can sometimes lead to confusion, especially when dealing with database configurations. One particular error that developers encounter is: "Cannot determine embedded database driver class for database type NONE."
Understanding the Error
When Spring Boot attempts to configure a data source automatically, it expects a certain environment. The error "Cannot determine embedded database driver class for database type NONE" typically arises when Spring Boot cannot determine the database type and is therefore unable to configure a suitable data source.
Here are some of the scenarios when this error might occur:
- Missing Driver Dependency: Spring Boot cannot autodetect an embedded database if the necessary driver dependencies are missing from the classpath.
- Incorrect Database Configuration: No explicit configuration is provided in the
application.propertiesorapplication.ymlfiles, leading Spring Boot to search for an embedded database when it cannot find one. - Unused Profile Activation: Profiles meant to switch data source configurations might not be activated correctly.
Spring Boot's AutoConfiguration
Spring Boot provides the spring-boot-starter-jdbc and spring-boot-starter-data-jpa starters, which are responsible for configuring a DataSource. By default, if these starters are on the classpath and an explicit DataSource is not configured, Spring Boot will attempt to detect an embedded database such as H2, HSQLDB, or Derby.
Spring Boot uses the following logic to determine the appropriate configuration:
- It checks the classpath for embedded database drivers like H2, HSQLDB, or Derby.
- If not found, the detection mechanism fails, and it defaults to reporting the "database type NONE."
Resolving the Error
Below are common steps to resolve this error:
1. Ensure the Correct Database Dependency
Ensure you have the necessary driver and embedded database dependencies. For example, for H2, include the following in your pom.xml:
2. Explicit Database Configuration
Override Spring Boot’s auto-configuration by explicitly providing the database configuration in application.properties or application.yml:
3. Activate Spring Profile
If using profiles, ensure correct activation:
Corresponding profile-specific properties should reside in application-dev.properties or similar.
4. Check for Application Context Issues
Ensure your application's context does not inadvertently exclude necessary configurations, which can happen due to misconfiguration of component scanning or improper context initialization.
Examples of Common Configurations
Here's a simple example of a project configured for H2 as the embedded DB:
pom.xml:
application.properties:
Summary Table
| Issue/Aspect | Description/Action |
| Missing Driver Dependency | Ensure driver dependencies for the intended database are included in your project. |
| Incorrect Database Configuration | Provide an explicit database configuration in application.properties or application.yml. |
| Profile Activation Problems | Activate the correct profile to use appropriate configurations. |
| Application Context Issues | Verify component scanning and context initialization are properly configured to include necessary beans. |
By understanding and addressing these areas, you can efficiently manage and rectify the "Cannot determine embedded database driver class for database type NONE" error in your Spring Boot applications. This understanding ensures more robust application configuration management, ultimately leading to a smoother development experience.
Related reading
- Spring Boot - Handle to Hibernate SessionFactory
- Spring Boot - Limit on number of connections created
- Spring boot - Not a managed type
- Spring boot and Flyway Clear database data before integration tests
- Spring Boot - custom 404 page with standalone tomcat
- Spring boot - custom variables in Application.properties
- Spring Boot - Error creating bean with name 'dataSource' defined in class path resource
- Spring Boot - How to log all requests and responses with exceptions in single place?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.