其他分享
首页 > 其他分享> > Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasou

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

作者:互联网

问题描述:

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,分布式,微服务。 

标签:jdbc,configure,embedded,no,spring,boot,hikari,datasource,mysql
来源: https://www.cnblogs.com/niugang0920/p/12186641.html