SpringBoot 2.x 通用 YML

1、application-database.yml

spring:
  datasource: # 数据源
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: root
    url: jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC # &serverTimezone=UTC 解决时区报错
    type: com.alibaba.druid.pool.DruidDataSource # 自定义数据源
    # Spring Boot 默认是不注入这些属性值的,需要自己绑定
    # druid 数据源专有配置
    initialSize: 5
    minIdle: 5
    maxActive: 20
    maxWait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL # 验证连接
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    # 配置监控统计拦截的filters
    #   stat:监控统计、
    #   log4j:日志记录、
    #   wall:防御 sql 注入
    # 如果允许时报错 java.lang.ClassNotFoundException:org.apache.log4j.Priority
    # 则导入 log4j 依赖即可,Maven 地址:https://mvnrepository.com/artifact/log4j/log4j
    filters: stat,wall,log4j
    maxPoolPreparedStatementPerConnectionSize: 20
    useGlobalDataSourceStat: true
    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500

2、application-mybatis-plus.yml

mybatis-plus:
  # 指定 MyBatis 的核心配置文件与 Mapper 映射文件
  mapper-locations: classpath:mappers/*.xml
  # 对应实体类的路径
  type-aliases-package: com.demo.entity
  # MyBatis 驼峰命名规则自动转换
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    map-underscore-to-camel-case: true

3、application-pagehelper.yml

# 配置 pagehelper
pagehelper:
  helper-dialect: mysql
  reasonable: true
  support-methods-arguments: true
  params: count=countSql

4、application-redis.yml

spring:
  # 缓存数据库
  redis:
    # Redis 数据库索引 (默认为 0)
    database: 0
    host: localhost
    port: 6379
    password:
    # 连接超时时间 (毫秒)
    timeout: 1000
    lettuce:
      pool:
        # 连接池最大连接数 (使用 负值 表示没有限制)
        max-active: 8
        # 连接池最大阻塞等待时间 (使用 负值 表示没有限制)
        max-wait: -1ms
        # 连接池最大空闲连接
        max-idle: 5
        # 连接池最小空闲连接
        min-idle: 0
      # 关闭超时时间
      shutdown-timeout: 100

5、合并 yml

server:
  port: 8001

spring:
  application:
    name: your project name
  profiles:
    include: database, mybatis-plus
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值