In this article, we’ll talk about the spring boot error Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured. This error occurs because the datasource configuration for the application is missing. The problem can be resolved Using two approaches, datasource configuration and disabling datasource auto configuration.

How to reproduce this problem

Create a spring boot application and include two maven dependencies, Spring Data JPA and MySQL Driver. The pom.xml file will contain the two dependencies spring-boot-starter-data-jpa and mysql-connector-java after you create the spring boot application. Run the spring boot application now. The error message will be displayed in the console window.



The error message Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured will appear in the console window, as shown below.



Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

Root Cause

The spring boot application has JPA configuration enabled. The spring boot application’s auto configuration will attempt to connect to the database. Datasource configurations such as database url, user name, password, database driver name, and so on are required to establish the database connection. The spring boot application searches configuration files such as and application.yaml for the datasource configuration. The file does not contain any datasource configurations. As a result, the spring boot application will throw the error Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

Solution 1

In the file, the datasource configuration is missing. To resolve this error, add the datasource configuration to the file. In the file, add the configuration properties listed below.


Solution 2

If you’re using the application.yaml file, add the following configuration to it. The spring boot application will look in the file first, then in the application.yaml file.

    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/testdb
    username: root
    password: password

Solution 3

Java code can be used to configure the datasource. The spring boot application framework will allow the datasource to be configured in the java files. The datasource configuration in java code is shown in the example below.

package com.yawintutor;

import javax.sql.DataSource;

import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class DataSourceConfiguration {
    public DataSource getDataSource() {
        return DataSourceBuilder.create()

Solution 4

The DataSourceAutoConfiguration is in charge of checking and connecting the database to the datasource. Exclude the configuration in the file to disable DataSourceAutoConfiguration.


Soution 5

DataSourceAutoConfiguration can be disabled by excluding it from the application.yaml file. To disable auto configuration, add the following yaml configuration to the spring boot application.yaml file.

    exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

Solution 6

DataSourceAutoConfiguration can also be disabled in the java file. Add the exclude configuration code to the spring boot application main class to disable auto configuration.

package com.yawintutor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class SpringBootJpaApplication {

	public static void main(String[] args) {, args);

Leave a Reply