Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasourc

Posted niugang0920

tags:

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

问题描述:

springboot版本 2.1.1

pom.xml配置

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

       <dependency>
           <groupId>mysql</groupId>
           <artifactId>mysql-connector-java</artifactId>
       </dependency>
</dependencies>
技术图片

application.properties

spring.datasource.hikari.jdbc-url=jdbc:mysql://127.0.0.1:3306/bootdb?serverTimezone=GMT%2B8&useUnicode=true&&characterEncoding=UTF-8
spring.datasource.hikari.username=root
spring.datasource.hikari.password=123456
spring.datasource.hikari.driver-class-name=com.mysql.jdbc.Driver
技术图片

在配置数据连接的时候报如下错误:

> Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could 

这是因为引入的spring-boot-starter-jdbc但是没有配置spring.datasource.url等信息报错的。(在我的application.properties中采用的hikari作为数据库连接)

 

解决办法:

第一种:

将配置信息改为:

#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/bootdb?serverTimezone=GMT%2B8&useUnicode=true&&characterEncoding=UTF-8
#spring.datasource.type=com.zaxxer.hikari.HikariDataSource
#spring.datasource.username=root
#spring.datasource.password=123456
技术图片

第二种:(去掉DataSourceAutoConfiguration的自动配置)

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

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

}
技术图片

                                                                               微信公众号

                                               技术图片技术图片?

                                                                             JAVA程序猿成长之路

                          分享资源,记录程序猿成长点滴。专注于Java,Spring,SpringBoot,SpringCloud,分布式,微服务。 

以上是关于Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasourc的主要内容,如果未能解决你的问题,请参考以下文章

struts报错严重: Dispatcher initialization failed Unable to load configuration.

Failed to upgrade Oracle Cluster Registry configuration(root.sh)

安装Intel HAXM:"failed to configure driver unknown error. failed to open driver"

Failed to configure a DataSource 'url' attribute问题解决

springboot启动报错:Failed to configure a DataSource

Springboot Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded