SpringBoot application 常用配置

application可以是 .yml和.properties

1、mybatis配置mapper.xml中使用的pojo包路径,配置后在.xml中不用使用带包名的路径

mybatis:
  type-aliases-package: com.kang.springboot04example.pojo

2、mybatis配置mapper.xml所在路径,当mapper.xml不在mapper.java同路径时需要配置

mybatis:
  mapper-location:classpath:mybatis/mapper/*.xml 

3、配置接收data格式

spring:
  mvc:
    format:
      date-time: yyyy-MM-dd HH:mm:ss

4、关闭模板引擎的缓存

spring:
  thymeleaf:
    cache: false

5、配置国际化数据

spring:
  messages:
    basename: i18n.login

6、配置JDBC+Druid

spring:
  datasource:
    username: root
    password: xiaokang123456
    #?serverTimezone=UTC解决时区的报错
    url: jdbc:mysql://localhost:3306/springboot?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
    driver-class-name: com.mysql.cj.jdbc.Driver
    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

猜你喜欢

转载自blog.csdn.net/qq_40197728/article/details/119770443