首页 > 解决方案 > 如何在spring boot application.yml中同时配置mongodb和postgres?

问题描述

我们有spring boot项目,我们需要在其中使用mongo和postgres,但我认为配置mongo和postgres详细信息applicaiton.yml失败,在我配置的下面,谁能帮我

spring:
    profiles: stage
    data:
      mongodb:
        host: mongodb-host
        port: 27017
        password: password
        username: username
        authentication-database: database
        database: database
    datasource:
        driver-class-name: org.postgresql.Driver
        url: postgres-url
        username: user-name
        password: password
        tomcat:
          validation-interval: 30000
          test-on-borrow: true
          validation-query: SELECT 1

当我启动我的 spring-boot 应用程序时,它无法启动并出现以下错误

Caused by: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.

有人可以帮忙吗

标签: springmongodbpostgresqlspring-boot

解决方案


解决方案 1:删除spring.datasource.driver-class-name属性

解决方案 2:将spring.datasource.url属性重命名为spring.datasource.jdbc-url.

对于解决方案 1,Spring Boot 将根据 spring.datasource.url 属性值找出默认的驱动程序类名称。


推荐阅读