Spring Boot Mongo DB .yml配置

时间:2019-05-30 04:41:45

标签: java mysql mongodb hibernate spring-boot

当我使用MySQL并休眠以进行春季引导时,我在.yml文件中使用以下配置

spring:
  datasource:
    url: jdbc:mysql://localhost/userName?zeroDateTimeBehavior=convertToNull
    username: userName
    password: password
    driverClassName: com.mysql.jdbc.Driver

  jpa:
    show-sql: false
    hibernate:
      dialect: org.hibernate.dialect.MySQLDialect
      format_sql: false
      ddl-auto: update 

如果它是mongoDB而不是MySQL,并且休眠,它将如何更改?

2 个答案:

答案 0 :(得分:0)

mongodb属性都以spring.data.mongodb为前缀。对于用户属性,您将使用

spring:
  data:
      mongodb:
        user: test
        password: passwordvalue
        uri: mongodb://host:27017/db

可用的mongodb属性列表在这里:

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

您可以在源代码中找到它们如何在github上加载:

https://github.com/spring-projects/spring-boot/blob/v2.1.5.RELEASE/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java

答案 1 :(得分:0)

您可以执行以下操作:

spring:
  data:
    mongodb:
      uri: mongodb://localhost:27017/yourDB