第一个springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no

Posted gaosimeng0627

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第一个springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no相关的知识,希望对你有一定的参考价值。

 

 

报错内容具体如下

***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
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
 
 
Action:
 
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).

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

翻译就是:无法配置DataSource:未指定‘url‘属性,也无法配置嵌入数据源。

就是在应用中没有配置datasource的一些相关属性,例如:地址值,数据库驱动,用户名,密码

SpringBoot的最大一个好处就是自动配置:所以我们只是需要给他配置文件的值,它就会自动配置。配置在application.properties文件中,不过也可以不配置,但是需要声明一下

启动类头部声明就可以了:

具体操作如下

1.找到main下的Application.java文件

技术图片

 

2.在该文件下的

@SpringBootApplication后添加
(exclude = DataSourceAutoConfiguration.class)

如下,然后重新启动项目就可以了

package com.example.demo;

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

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class DemoApplication {

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

}

以上是关于第一个springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot项目启动报错:javax.mail.AuthenticationFailedException: 535 5.7.8 authentication failed

Springboot项目启动报错Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded d

springboot启动报错 Failed to configure a DataSource: 'url' attribute is not specified and no emb

Springboot启动报错:child container failed during start

SpringBoot中使用Kafka报错:Failed to construct kafka consumer

SpringBoot启动报错Failed to determine a suitable driver class