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

2年前 (2022) 程序员胖胖胖虎阿
275 0 0

今天在学习springCloud配置中心的时候遇到一个异常:

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.......

字面意思是:无法配置DataSource:未指定'url'属性,也无法配置嵌入数据源。

那很明显 就是说 你的application.yml文件中没有指定数据库的配置,url,driver这些东西

但是很奇怪~

我用的是springCloud的配置中心 这些配置我都是配置在码云上面的,且我的配置中心也可以正常启动且访问到数据:

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

确认我配置中心的数据库信息没错之后,那么我问题就只剩下一个了

就是我的提供者 读不到我配置中心里面的user-provider-dev.yml的数据

所以我先确认服务提供者的bootstrap.yml的配置有没有错误

# 注释版本
spring:
  cloud:
    config:
      name: user-provider # 与远程仓库中的配置文件的application保持一致,{application}-{profile}.yml
      profile: dev # 远程仓库中的配置文件的profile保持一致
      label: master # 远程仓库中的版本保持一致
      discovery:
        enabled: true # 使用配置中心
        service-id: config-server # 配置中心服务id
#向Eureka服务中心集群注册服务
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:7001/eureka

确认没有错误后,我百思不得其解,上网百度了很多博客他们说让我在启动类加上注解

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

或者是让我注释掉mybatis的依赖

 但是我dao层没有使用持久层框架mybatis且又需要JPA  我就尝试注释掉了jpa 结果可想而知编译时就报错了。

最后最后!我才发现!究其原因我的服务提供者没有支持SpringCloud配置中心的依赖 导致我读不到我配置中心的数据啊啊啊啊

竟然如此粗心大意 ,我自己也是对自己无语了哈哈哈

最后我在服务提供者pom.xml文件中加入依赖

    <!--spring cloud 配置中心-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

注意:添加完依赖记得刷新maven哦~

然后启动提供者 问题解决!

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

 今天的博客就分享到这里啦,虽然这个报错特别的低级,特别的不应该,但是就是因为一时的粗心大意导致找了我45分钟,主要还是分享找错误的一个思路 嘿嘿....

相关文章

暂无评论

暂无评论...