DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Be Punctual! Avoiding Kotlin’s lateinit In Spring Boot Testing
  • Spring Boot: How To Use Java Persistence Query Language (JPQL)
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements

Trending

  • Agentic AI for Automated Application Security and Vulnerability Management
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 1
  • Kullback–Leibler Divergence: Theory, Applications, and Implications
  • Simplifying Multi-LLM Integration With KubeMQ
  1. DZone
  2. Coding
  3. Java
  4. Spring Boot Error: Creating a Bean With 'DataSource' Defined in DataSourceAutoConfiguration

Spring Boot Error: Creating a Bean With 'DataSource' Defined in DataSourceAutoConfiguration

Learn more about the DataSourceAutoConfiguration error in Spring Boot and how to troubleshoot it.

By 
Javin Paul user avatar
Javin Paul
·
Updated Mar. 13, 25 · Tutorial
Likes (12)
Comment
Save
Tweet
Share
216.9K Views

Join the DZone community and get the full member experience.

Join For Free

If you are using Spring Boot and getting errors like "Cannot determine embedded database driver class for database type NONE," or "Error creating a bean with name 'dataSource' defined in class path resource DataSourceAutoConfiguration," then you have come to the right place. In this article, we'll examine different scenarios in which this Spring Boot error comes up and what you can do to solve it. The general reason for this error is Spring Boot's auto-configuration, which is trying to automatically configure a DataSource for you but doesn't have enough information. It is automatically trying to create an instance of DataSourceAutoConfiguration bean and it's failing.

Like other Spring Frameworks errors, the stack trace looks quite messy, something that they could have improved with Spring Boot, but here are these two errors I mentioned above.

Let's see what the stack trace looks like in general:

Shell
 
@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class SpringBootDemo {

  public static void main(String[] args) {
   SpringApplication.runSpringBootDemo.class, args);
  }

}


It is important to keep in mind that these errors can be intimidating if you are completely new to the Spring Framework. In that case, I suggest you go through a comprehensive Spring Boot course online. Now, let's see some common causes of this error and what you can do to solve this problem.


Spring MVC, Spring Boot, and REST Controllers*

*Affiliate link. See Terms of Use.


1) Spring Boot Error Due to Starter Dependency

Some of my friends get this error even if they don't need a database. The main reason they were getting this error was because of a starter dependency. For example, some of them included spring-boot-starter-data-jpa, which then included hibernate-entitymanager.jar, and they didn't have additional things need to set that up.

Sometimes, including incorrect Starter POM, can also solve this problem like adding spring-boot-starter-jdbc  instead of spring-boot-starter-data-jpa dependency.

Spring Boot auto-configuration is triggered by JAR dependencies present in the classpath, and if it pulls something you don't need, then this type of error can occur.

Spring Boot Starter POM Dependency diagram

2) Due to Missing Dependency

Sometimes, you do need a database but you forgot to include the driver JAR file into the classpath, which can also cause this error. For example, you have specified the following properties in the application.properties, Spring Boots configuration file but didn't include the corresponding MySQL JDBC driver into the classpath:

Shell
 
@Configuration
@EnableAutoConfiguration(
exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class SpringBootDemo {

  public static void main(String[] args) {
     SpringApplication.runSpringBootDemo.class, args);
  }

}


In order to solve this error, either you need to include the correct Starter POM dependency, or you need to manually add the MySQL JDBC JAR file into the classpath. If you are interested, you can check out this tutorial to learn more about how to connect a Java application to a database using a MySQL database.

3) Due to Missing Configuration in Application.properties

Spring Boot is good at configuring in-memory databases like H2, HSQLDB, Derby, etc., and it can configure them just by adding their JAR files into the classpath, but for others, you need to give Spring Boot additional details like URL, DriverClass name, etc.

You can do that by adding some properties to the application.properties file with the spring.datasource prefix, as shown in the following example:

Shell
 
spring.datasource.url = jdbc:mysql://localhost/abc
spring.datasource.name=testme
spring.datasource.username=xxxx
spring.datasource.password=xxxx
spring.datasource.driver-class-name= com.mysql.jdbc.Driver spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect


This will provide the Spring Boot auto-configuration component to configure the database for you. If you want to learn more about how auto-configuration works in Spring Boot, I suggest you go through a comprehensive Spring Boot course like Spring Boot: Efficient Development, Configuration, and Deployment on Pluralsight, which will also teach you the details behind @EnableAutoConfiguration   by writing your own auto configurations.

4) Exclude DataSourceAutoConfiguration

Sometimes, excluding DataSourceAutoConfigution can also solve this problem, especially if you don't need a database. This will prevent Spring Boot from automatically configuring the database and there won't be any errors. You can disable auto-configuration for certain classes by using the exclude attribute of the @EnableAutoConfiguration annotation of Spring Boot, as shown below:

Shell
 
org.springframework.beans.factory.BeanDefinitionStoreException: 
Factory method [public javax.sql.DataSource 
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$N
onEmbeddedConfiguration.dataSource()] threw exception; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Cannot determine embedded database driver class for database type NONE. 
  If you want an embedded database please put a supported one on the classpath.:

[INFO] org.springframework.beans.factory.BeanCreationException: 
Cannot determine embedded database driver class for database type NONE. 
If you want an embedded database please put a supported one on the classpath.


You can even exclude more than one classes using exclude attribute with @EnableAutoConfiguration as shown below:

Shell
 
spring.datasource.url = jdbc:mysql://localhost/test

spring.datasource.driver-class-name= com.mysql.jdbc.Driver


That's all for today on how to solve the "Cannot determine embedded database driver class for database type NONE" or "Error creating a bean with name 'dataSource' defined in class path resource DataSourceAutoConfiguration" problem. In most cases, it is because auto-configuration doesn't have enough details required to configure the database, but sometimes, it's also the accidental trigger of database auto-configuration, which can be disabled using the exclude attribute of @EnableAutoConfiguration annotation.

Other Java and Spring Boot articles you may like:

  • 5 Spring Boot Features Every Java Developer Should Know (features)
  • Top 5 Free Courses to learn Spring and Spring Boot in 2025 (courses)
  • 5 Course to Master Spring Boot online in 2025 (courses)
  • 10 Things Java Developer should learn in 2025 (goals)
  • 10 Tools Java Developers use in their day-to-day life (tools)
  • 10 Tips to become a better Java developer in 2025 (tips)
  • 3 Best Practices Java Programmers can learn from Spring (best practices)
  • Top 5 Spring Boot Annotations Java Developers should know (annotations)
  • 5 books to learn Spring Boot and Spring Cloud (books)
  • 5 courses to learn Spring Boot in depth (courses)

Thanks for reading this article! If you liked my explanation and solution of this Spring Boot error, then please share with your friends and colleagues.

Spring Framework Spring Boot Java (programming language)

Published at DZone with permission of Javin Paul, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Be Punctual! Avoiding Kotlin’s lateinit In Spring Boot Testing
  • Spring Boot: How To Use Java Persistence Query Language (JPQL)
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!