Springboot2.4.4 application.yml YAML 模板 笔记

相关笔记: springboot2.4.4 application.properties 模板 笔记


YAML 基本要点

  1. 键 冒号空格
  2. 层级用左边空格区分, 不能用 Tab 制表符
  3. 字符串值可以不加单双引号, 如果有空格就要加

基础模板 application.yml

spring.application.name: ApplicationName
server:
  # Network address to which the server should bind.
  # 网络地址绑定 默认无
  address:
  # 服务器的HTTP端口,默认为8080
  port: 80
  # Value to use for the Server response header (if empty, no header is sent).
  # 可以在response的头加东西, 默认没有
  server-header: 
  servlet:
    # ContentPath 可以没/
    context-path: /
  # tomcat相关
  tomcat:
  	# Character encoding to use to decode the URI.
    # URI解码的字符集 默认UTF-8
    uri-encoding: UTF-8
    # Maximum number of connections that the server accepts and processes at any given time. Once the limit has been reached, the operating system may still accept connections based on the "acceptCount" property.
    # 服务器在任何给定时间接受和处理的最大连接数。 一旦达到限制,操作系统仍然可以基于“ acceptCount”属性接受连接。 
    # 最大连接数,默认8192
    max-connections: 8192
    # Maximum queue length for incoming connection requests when all possible request processing threads are in use.
    # 使用所有可能的请求处理线程时,传入连接请求的最大队列长度。 
    # 默认 100
    accept-count: 100
    # Amount of time the connector will wait, after accepting a connection, for the request URI line to be presented.
    # 在接收一个连接后,连接器会等待一段时间, 直到请求的URI提交上来
    # 建立tcp后,等待http的时间, 默认什么也没有
    connection-timeout:
    # Maximum size of the form content in any HTTP post request.
    # 任何HTTP发布请求中表单内容的最大大小。 
    # 会限制单个上传文件大小 默认 2m 两兆
    max-http-form-post-size: 20m
    # Maximum amount of request body to swallow.
    # 请求体的最大吞吐量
    # 会限制一次上传中所有文件的总大小, 默认 2m 两兆
    max-swallow-size: 20m
    # Maximum number of idle processors that will be retained in the cache and reused with a subsequent request. When set to -1 the cache will be unlimited with a theoretical maximum size equal to the maximum number of connections.
    # 将保留在缓存中并在后续请求中重用的最大空闲处理器数。 设置为-1时,高速缓存将不受限制,其理论最大大小等于最大连接数。 
    # 默认 200
    processor-cache: 200
    # Whether requests to the context root should be redirected by appending a / to the path. When using SSL terminated at a proxy, this property should be set to false.
    # 是否将requests到context root的请求重定向加上一个斜杠/ , 当用SSL终端代理时 , 应当设为 false
    # 默认 true
    redirect-context-root: true
    # Tomcat线程
    threads:
      # 最大线程数,默认为200
      max: 32
      # 初始线程数,默认值10
      min-spare: 3

spring:
  profiles:
    # Comma-separated list of active profiles. Can be overridden by a command line switch.
    # 逗号分隔的活动配置profile列表。 可以被命令行开关覆盖。
    active:
    # Unconditionally activate the specified comma-separated list of profiles (or list of profiles if using YAML).
    # 无条件激活指定的逗号分隔的profile列表(如果使用YAML,则激活配置文件列表)。 
    include:
    

连接数据库的模板

spring.datasource 基本 默认方式连接数据库

spring:
  datasource:
  
    #Name of the datasource. Default to "testdb" when using an embedded database.
    #给数据源取名, 默认 testdb
    name: datasource001
    
    #Whether to generate a random datasource name.
    #是否给数据源生成一个随机名称 , 默认 true
    generate-unique-name: false
    
    # 数据源类型
    # Hikari : com.zaxxer.hikari.HikariDataSource
    # 阿里巴巴Druid : com.alibaba.druid.pool.DruidDataSource
    type:
    
    #Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.
    #指定driver的类名,默认从jdbc url中自动探测.
    #Mysql8 : com.mysql.cj.jdbc.Driver
    #Mysql5.7 : com.mysql.jdbc.Driver
    #微软SqlServer : com.microsoft.sqlserver.jdbc.SQLServerDriver
    driver-class-name:
    
    #JDBC URL of the database. 数据库的JDBC URL
    # MySQL8.0.x : jdbc:mysql://localhost/dbName?user=minty&password=greatsqldb
    # MySql5.x : jdbc:mysql://localhost/dnName?user=minty&password=greatsqldb
    # SqlServer2019 : jdbc:sqlserver://localhost:1433; DatabaseName=test
    # SqlServer2000 : jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=test
    url:
    
    username: 数据库用户名
    password: 数据库密码
    

默认连接池 Hikari 模板


spring.datasource.type: com.zaxxer.hikari.HikariDataSource

spring.datasource.hikari:
  # 给该连接池取个名字
  pool-name: Hikari001

# 数据库jdbc驱动
# MySql8 : com.mysql.cj.jdbc.Driver
# MySql5 : com.mysql.jdbc.Driver
# SqlServer : com.microsoft.sqlserver.jdbc.SQLServerDriver
# Oracle : oracle.jdbc.driver.OracleDriver
  driver-class-name: 


#数据库jdbc url
# MySql8 : jdbc:mysql://HostName:3306/DatabaseName
# MySql8 : jdbc:mysql://HostName:3306/DatabaseName?autoReconnect=true&characterEncoding =UTF-8&zeroDateTimeBehavior=CONVERT_TO_NULL&connectionTimeZone=Asia/Shanghai&allowMultiQueries=true&maxRows=1000
# MySql5 : jdbc:mysql://HostName:3306/DatabaseName?autoReconnect=true&characterEncoding =UTF-8&zeroDateTimeBehavior=CONVERT_TO_NULL&connectionTimeZone=Asia/Shanghai&allowMultiQueries=true&maxRows=1000
# SqlServer : jdbc:sqlserver://localhost:1433; DatabaseName=test
# Oracle : jdbc:oracle:thin:127.0.0.1:port:dbname
  jdbc-url: 

#数据库用户名
  username: root
#数据库密码
  password: password


# 用于设置 : com.zaxxer.hikari.HikariConfig 的 private boolean isAutoCommit;
# 此属性控制从池返回的连接的默认自动提交行为。它是一个布尔值。 默认值:true
# default = true
  auto-commit: true

# 用于设置 : com.zaxxer.hikari.HikariConfig 的 private volatile int maxPoolSize;
# 此属性控制池中连接的最大生存期。正在使用的连接永远不会退休,只有在关闭后才会被删除。在逐个连接的基础上,应用较小的负面衰减来避免池中的大量消失。 我们强烈建议设置此值,并且应该比任何数据库或基础设施规定的连接时间限制短几秒。 值为0表示没有最大寿命(无限寿命),当然是idleTimeout设定的主题。 默认值:1800000(30分钟)
# default = 10
  maximum-pool-size: 100


# 用于设置 : com.zaxxer.hikari.HikariConfig 的  private volatile int minIdle;
# minIdle初始值-1 , 后来if (minIdle < 0 || minIdle > maxPoolSize) {     minIdle = maxPoolSize;      } , 设为了maxPoolSize
# 该属性控制HikariCP尝试在池中维护的最小空闲连接数。如果空闲连接低于此值并且连接池中的总连接数少于此值maximumPoolSize,则HikariCP将尽最大努力快速高效地添加其他连接。但是,为了获得最佳性能和响应尖峰需求,我们建议不要设置此值,而是允许HikariCP充当固定大小的连接池。 默认值:与maximumPoolSize相同
# default  minimum-idle = maximum-pool-size
  minimum-idle: 10


# when minimum-idle < maximum-pool-size
# idel connection life time
# must>10000 ; default=600000(10 minute) ; 0 is infinity
  idle-timeout: 30000


# 用于设置 : com.zaxxer.hikari.HikariConfig 的 private volatile long idleTimeout;
# 此属性控制允许连接在池中闲置的最长时间。 此设置仅适用于minimumIdle定义为小于maximumPoolSize。一旦池达到连接,空闲连接将不会退出minimumIdle。连接是否因闲置而退出,最大变化量为+30秒,平均变化量为+15秒。在超时之前,连接永远不会退出。值为0意味着空闲连接永远不会从池中删除。允许的最小值是10000ms(10秒)。 默认值:600000(10分钟)
# connection max lifet time (millisecond)  default 1800000(30 minute)
  max-lifetime: 1800000


# 用于设置 : com.zaxxer.hikari.HikariConfig 的 private volatile long connectionTimeout;
# 此属性控制客户端(即您)将等待来自池的连接的最大毫秒数。如果在没有可用连接的情况下超过此时间,则会抛出SQLException。最低可接受的连接超时时间为250 ms。 默认值:30000(30秒)
# dateSource.getConnection() timeout must>250ms default 30000(30 second)
  connection-timeout: 258


# 用于设置 : com.zaxxer.hikari.HikariConfig 的  private String connectionInitSql;
# 该属性设置一个SQL语句,在将每个新连接创建后,将其添加到池中之前执行该语句。如果这个SQL无效或引发异常,它将被视为连接失败并且将遵循标准重试逻辑。 默认值:无
  connection-init-sql: 


# 用于设置 : com.zaxxer.hikari.HikariConfig 的 private String connectionTestQuery;
# 设置要执行的SQL查询以测试连接的有效性。 在某些数据库上,使用JDBC4 Connection.isValid()方法测试连接有效性可能更有效,因此建议使用。 
# 如果您的驱动程序支持JDBC4,我们强烈建议您不要设置此属性。这是针对不支持JDBC4的“传统”驱动程序Connection.isValid() API。这是在连接从池中获得连接以确认与数据库的连接仍然存在之前将要执行的查询。再一次,尝试运行没有此属性的池,如果您的驱动程序不符合JDBC4的要求,HikariCP将记录一个错误以告知您。 默认值:无
  connection-test-query: SELECT 1


      

阿里 Druid

druid-mysql8.0.22

# 数据源配置
spring:
  application:
    name: springboot-test-exam1
  datasource:
    # 使用阿里的Druid连接池
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    # 填写你数据库的url、登录名、密码和数据库名
    url: jdbc:mysql://localhost:3306/guajava?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
    username: root
    password: 123456
    druid:
      # 连接池的配置信息
      # 初始化大小,最小,最大
      initial-size: 5
      min-idle: 5
      maxActive: 20
      # 配置获取连接等待超时的时间
      maxWait: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      timeBetweenEvictionRunsMillis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      minEvictableIdleTimeMillis: 300000
      validationQuery: SELECT 1 FROM DUAL
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
      # 打开PSCache,并且指定每个连接上PSCache的大小
      poolPreparedStatements: true
      maxPoolPreparedStatementPerConnectionSize: 20
      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
      filters: stat,wall
      # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
      connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
      # 配置DruidStatFilter
      web-stat-filter:
        enabled: true
        url-pattern: "/*"
        exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
      # 配置DruidStatViewServlet
      stat-view-servlet:
        url-pattern: "/druid/*"
        # IP白名单(没有配置或者为空,则允许所有访问)
        allow: 127.0.0.1,192.168.163.1
        # IP黑名单 (存在共同时,deny优先于allow)
        deny: 192.168.1.73
        #  禁用HTML页面上的“Reset All”功能
        reset-enable: false
        # 登录名
        login-username: admin
        # 登录密码
        login-password: 123456
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kfepiza

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值