常用的yml配置

傻男人 1年前 ⋅ 718 阅读

常用的yml配置

一、redis

spring:
  redis:
    host: localhost
    port: 6379
    shutdown-timeout: 100
    database: 3
    lettuce:
      pool:
        max-idle: 8
        min-idle: 0
        max-active: 8
        max-wait: 10000
    timeout: 10000
    password: 123456

二、mybatis-plus

mybatis-plus:
  # xml扫描,多个目录用逗号或者分号分隔(告诉 Mapper 所对应的 XML 文件位置)
  mapper-locations: classpath*:mapper/*Mapper.xml
  #实体扫描,多个package用逗号或者分号分隔
  type-aliases-package: xxx.process.entity
  typeEnumsPackage: xxx.commons.constant,com.baomidou.springboot.entity.enums
  global-config:
    #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
    id-type: 2
    #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
    field-strategy: 2
    #驼峰下划线转换
    db-column-underline: true
    #刷新mapper 调试神器
    refresh-mapper: true
    #数据库大写下划线转换
    #capital-mode: true
    #序列接口实现类配置
    #key-generator: com.baomidou.springboot.xxx
    #逻辑删除配置(下面3个配置)
    logic-delete-value: 1
    logic-not-delete-value: 0
    #数据库类型
    db-type: MYSQL
    #自定义填充策略接口实现
    #meta-object-handler: xxxx.config.CommonFiledMetaObjectHandler
    #自定义SQL注入器
    sql-injector: xxx.mybatisplus.BaseDtoSqlInjector
  configuration:
    # 关闭MP3.0自带的banner
    banner: false
    #配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as: select user_id as userId)
    map-underscore-to-camel-case: true
    cache-enabled: false
    #配置JdbcTypeForNull, oracle数据库必须配置
    #jdbc-type-for-null: 'null'
    # 返回map时true:当查询数据为空时字段返回为null,false:不加这个查询数据为空时,字段将被隐藏
    call-setters-on-nulls: true
    default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler
    #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

三、druid

spring:
  datasource:
    druid:
      driverClassName: com.mysql.cj.jdbc.Driver
      filters: stat,wall
      filter:
        stat:
          log-slow-sql: true
          slow-sql-millis: 2000
          merge-sql: true
      initialSize: 3
      maxActive: 20
      maxPoolPreparedStatementPerConnectionSize: 50
      maxWait: 60000    #获取连接等待超时时间
      minEvictableIdleTimeMillis: 300000
      minIdle: 1
      poolPreparedStatements: false #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
      #sql监控
      stat-view-servlet:
        allow: 127.0.0.1
        enabled: true
        login-password: druid
        login-username: druid
        reset-enable: true
        url-pattern: /druid/*
      testOnBorrow: false
      testOnReturn: false
      testWhileIdle: true
      timeBetweenEvictionRunsMillis: 60000
      validationQuery: select 'x'
      web-stat-filter:
        enabled: true
        exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
        profile-enable: true
        session-stat-enable: true
        session-stat-max-count: 1000
        url-pattern: /*

四、rabbitmq

spring:
  rabbitmq:
    host: 139.224.247.139
    port: 5672
    username: admin
    password: anjingsi123
    virtual-host: /
    publisher-confirm-type: correlated
    publisher-returns: true
    listener:
      simple:
        retry:
          enabled: true
          max-attempts: 5
          max-interval: 10000   # 重试最大间隔时间
          initial-interval: 2000  # 重试初始间隔时间
          multiplier: 2 # 间隔时间乘子,间隔时间*乘子=下一次的间隔时间,最大不能超过设置的最大间隔时间

五、eureka

eureka:
  instance:
    prefer-ip-address: true
    hostname: ${spring.application.name}
    instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://zhcf:zhcf123@192.168.0.89:8761/eureka/

六、gateway

spring:
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          lower-case-service-id: true
      routes:
        - id: process
          uri: lb://process
          filters:
            - StripPrefix=1
          predicates:
            - Path=/process/**

七、feign

feign:
  httpclient:
    connection-timeout: 10000
    enabled: true

八、ribbon

ribbon:
  ReadTimeout: 60000
  ConnectTimeout: 10000 #httpclient 有效,okHttp 无效。
  MaxAutoRetries: 0
  MaxAutoRetriesNextServer: 0
  OkToRetryOnAllOperations: false
  max-per-route-connections: 50
  max-total-connections: 300
  http:
    client:
      enabled: true

九、hystrix

hystrix:
  shareSecurityContext: true
  command:
    default:
      circuitBreaker:
        requestVolumeThreshold: 20
        sleepWindowInMilliseconds: 5000 #熔断后恢复
        forceClosed: true
      execution:
        timeout:
          enabled: true #是否开启超时熔断
        isolation:
          thread:
            timeoutInMilliseconds: 10000 #超时时间
  threadpool:
    default:
      allowMaximumSizeToDivergeFromCoreSize: true #200 #并发执行的最大线程数,默认10
      maxQueueSize: 1000 #BlockingQueue的最大队列数,默认值-1
      queueSizeRejectionThreshold: 800 #即使maxQueueSize没有达到,达到queueSizeRejectionThreshold该值后,请求也会被拒绝,默认值5

其他通用的配置

spring:
  jackson:
    #default-property-inclusion: non_null  null不返回给前端
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss

  servlet:
    multipart:
      max-request-size: 20MB
      max-file-size: 10MB
      file-size-threshold: 0
      enabled: true

http:
  #最大连接数
  maxTotal: 100
  #并发数
  defaultMaxPerRoute: 20
  #创建连接的最长时间
  connectTimeout: 1000
  #从连接池中获取到连接的最长时间
  connectionRequestTimeout: 500
  #数据传输的最长时间
  socketTimeout: 10000
  #提交请求前测试连接是否可用
  staleConnectionCheckEnabled: true

management:
  endpoints:
    web:
      exposure:
        include: "*"

全部评论: 0

    我有话说: