springboot的 yaml 配置文件:resources/application.yml常用配置

118 阅读2分钟

springboot的yaml配置文件:resources/application.yml常用配置示例:


spring:
  mvc:
    #static-path-pattern: /learn/** #修改静态资源访问的路径/前缀
    hiddenmethod:
      filter:
        enabled: true #启用了 HiddenHttpMethodFilter,开启页面表单的 Rest 功能
    view: #配置视图解析器
      suffix: .html
      prefix: / #这里是需要注意 prefix 需要和当前的 static-path-pattern 一致
    contentnegotiation:
      favor-parameter: true #开启基于请求参数的内容协商功能 示例:localhost:8080/get/monster?format=json
      parameter-name: hahaformat #指定一个内容协商的参数名 示例:localhost:8080/get/monster?hahaformat=json
  web:
    resources:
      #修改/指定 静态资源访问路径/位置
      static-locations: [classpath:/META-INF/resources/, classpath:/resources/, classpath:/static/, classpath:/public/]

  servlet:
    multipart:
      max-file-size: 10MB #单个文件的最大上限
      max-request-size: 100MB #单个请求的文件总大小上限
      
  datasource: #配置mysql数据源
    #如果没有使用 useSSL=true, 会报红警告
    url: jdbc:mysql://localhost:3306/spring_boot?useUnicode=true&characterEncoding=utf-8&useSSL=true
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver    
    #配置druid
    druid:
      stat-view-servlet:
        enabled: true
        login-username: jack
        login-password: 666
        reset-enable: false
      web-stat-filter: #配置web监控
        enabled: true
        url-pattern: "/*"
        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
      filter:
        stat: #配置sql监控
          slow-sql-millis: 1000 #慢查询
          log-slow-sql: true #慢查询日志
          enabled: true
        wall: #配置防火墙
          enabled: true
          config:
            drop-table-allow: false #数据表的删除语句拦截



server:
  port: 9999  #配置端口
  tomcat:
    threads:
      max: 10  #最大的工作线程,默认是200
      min-spare: 5  #最小工作线程,默认是10
    accept-count: 200  #tomcat启动的线程达到最大值,接受排队的请求个数
    max-connections: 2000  #最大连接数,并发数
    connection-timeout: 10000  #建立连接的超时时间,单位是毫种

#mybatis配置
mybatis:
  mapper-locations: classpath:mapper/*.xml #指定要扫描的Xxxmapper.xml文件
  #通过config-location可以指定mybatis-config.xml,可以以传统的方式来配置mybatis
  #config-location: classpath:mybatis-config.xml
  #我们也可以直接在application.yml进行配置
  #举例说明1.比如配置原来的typeAliases type-aliases-package:com.hspedu.springboot.mybatis.bean
  type-aliases-package: com.hspedu.springboot.mybatis.bean
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #举例说明2 配置输出底层的原生sql

  #配置mybatis的两种方式的选择:如果配置比较简单,就直接在application.yml配置
  #如果配置内容比较多,可以考虑单独的做一个mybatis-config.xml

#mybatis-plus配置
mybatis-plus:
  configuration:
    #这里我们配置输出底层的sql,方便我们观察sql
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl