【问题标题】:Spring boot Failed to configure a DataSource: 'url' attribute is not specifiedSpring boot 配置数据源失败:未指定“url”属性
【发布时间】:2019-10-20 11:47:00
【问题描述】:

我的项目昨天运行正常,今天运行突然报错。

2019-06-04 19:09:57.206 INFO 18231 --- [restartedMain] ConditionEvaluationReportLoggingListener:

启动 ApplicationContext 时出错。显示条件报告 在启用“调试”的情况下重新运行您的应用程序。 2019-06-04 19:09:57.207 错误 18231 --- [restartedMain] o.s.b.d.LoggingFailureAnalysisReporter:

***************************应用程序启动失败


说明:

未能配置数据源:未指定“url”属性并且 无法配置嵌入式数据源。

原因:无法确定合适的驱动程序类

行动:

考虑以下几点:如果您想要一个嵌入式数据库(H2、HSQL 或 德比),请把它放在类路径上。如果您有数据库设置 要从特定配置文件加载,您可能需要激活它(不 个人资料当前处于活动状态)。

进程以退出代码 0 结束

我的配置文件application.yml

spring:
  jpa:
    database-platform: org.hibernate.dialect.PostgreSQL9Dialect
    database: postgresql
  datasource:
    username: postgres
    password: adminadmin
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/postgres

我的依赖项中有 postgresql。

 implementation "org.postgresql:postgresql:42.2.5" // PostgreSQL driver

我尝试重建,无效并重新启动,没有工作。

【问题讨论】:

  • 你是否包含 implementation('org.springframework.boot:spring-boot-starter-data-jpa') ?
  • 当然,应用程序昨天运行良好。
  • 您只能检查您是否更改了 Gradle 中的任何内容?
  • 没有改变。
  • @Kata 它可以工作,但我必须重置所有 IDE 配置。这个问题的原因是什么?

标签: java spring-boot


【解决方案1】:

在 yml 中尝试以下操作

spring:
  jpa:
    database-platform: org.hibernate.dialect.PostgreSQL9Dialect
    database: POSTGRESQL
  datasource:
    username: postgres
    password: adminadmin
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/postgres

并确保 postgress.jar 位于应用程序的类路径中,并且 tomcat 正确地使用它。

【讨论】:

    【解决方案2】:

    **使用SpringBoot连接mongo db报错的解决方法在你的主类中使用下面的代码**

    @SpringBootApplication**(exclude = DataSourceAutoConfiguration.class)**

    【讨论】:

      猜你喜欢
      • 2023-02-07
      • 2020-04-26
      • 2018-12-15
      • 1970-01-01
      • 2019-08-24
      • 2021-03-18
      • 1970-01-01
      • 2023-02-21
      • 2020-10-30
      相关资源
      最近更新 更多