SpringBoot 的.yml配置文件通用模板

🌷🍁 博主猫头虎 带您 Go to New World.✨🍁
🦄 博客首页——猫头虎的博客🎐
🐳《面试题大全专栏》 文章图文并茂🦕生动形象🦖简单易学!欢迎大家来踩踩~🌺
🌊 《IDEA开发秘籍专栏》学会IDEA常用操作,工作效率翻倍~💐
🌊 《100天精通Golang(基础入门篇)》学会Golang语言,畅玩云原生,走遍大小厂~💐

🪁🍁 希望本文能够给您带来一定的帮助🌸文章粗浅,敬请批评指正!🍁🐥

Spring Boot的.yml配置文件通用模板

摘要:

本篇博客将提供一个通用的.yml配置文件模板,适用于Spring Boot项目中的各种配置需求。我们将分享一个基本的模板,帮助您快速开始编写配置文件,以满足您的项目需求。

引言:

Spring Boot使用.yml配置文件来管理应用程序的配置。为了方便开发,一个通用的配置文件模板可以帮助您快速启动新的项目,同时也可以保持一致的配置风格。本文将为您提供一个基本的.yml配置文件模板,适用于大多数Spring Boot项目。

配置方法:

方法一

以下是一个通用的.yml配置文件模板,您可以根据需要进行修改和扩展:

server:
  port: 8080

spring:
  application:
    name: your-application-name
  datasource:
    url: jdbc:mysql://localhost:3306/your-database
    username: your-username
    password: your-password
    driver-class-name: com.mysql.cj.jdbc.Driver
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
  profiles:
    active: dev

logging:
  level:
    root: INFO
    org.springframework: INFO

# Add more configuration properties here
  • server节点配置为您希望的端口。
  • spring节点下,配置应用程序的名称、数据库连接等。
  • 可以根据需求添加更多的配置项,例如Redis、消息队列等。

方法二

SpringBoot 的配置文件通用模板

在这里插入图片描述

application.yml 注意事项

在application.yml 文件书写注意:
  1. 不同“等级” 用冒号隔开
  2. 次等级的前面是空格,不能使用制表符(tab)
  3. 冒号之后如果有值,那么冒号和值之间至少有一个空格,不能紧贴着


#服务器设置-----------------------
server:
  port: 9090
  servlet:
    #热部署
    jsp:
      init-parameters:
        development: true
    # post表单提交乱码
    context-path: /user
  tomcat:
    uri-encoding: UTF-8


#Spring设置-----------------------
spring:
  #编码规则
  http:
    encoding:
      charset: UTF-8
      force: true
      #全局收参日期格式
  mvc:
    date-format: yyyy-MM-dd
    #视图解析器
    view:
      prefix: /
      suffix: .jsp
      #配置数据源(读写分离数据源)
  datasource:
    #配置自定义数据源1
    master:
      type: com.alibaba.druid.pool.DruidDataSource
      username: root
      password: 0
      driver-class-name: com.mysql.jdbc.Driver
      jdbc-url: jdbc:mysql://10.10.0.151:3306/project?useUnicode=true&characterEncoding=UTF8&serverTimezone=UTC&useSSL=false
    #配置自定义数据源2
    slave1:
      type: com.alibaba.druid.pool.DruidDataSource
      username: root
      password: 0
      driver-class-name: com.mysql.jdbc.Driver
      jdbc-url: jdbc:mysql://10.10.0.152:3306/project?useUnicode=true&characterEncoding=UTF8&serverTimezone=UTC&useSSL=false
    #配置自定义数据源3
    slave2:
      type: com.alibaba.druid.pool.DruidDataSource
      username: root
      password: 0
      driver-class-name: com.mysql.jdbc.Driver
      jdbc-url: jdbc:mysql://10.10.0.152:3306/project?useUnicode=true&characterEncoding=UTF8&serverTimezone=UTC&useSSL=false



    #Mycat数据源
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://10.10.0.151:8066/mycat #连接mycat逻辑库
    username: root
    password: root
  #单机数据源
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=UTF8&serverTimezone=UTC&useSSL=false
 #   username: root
 #   password: 123

 # Mycat 数据源

  #出参的全局格式
  jackson:
    date-format: yyyy-MM-dd
    time-zone: GMT+8
  #文件上传配置
  servlet:
    multipart:
      enabled: true
      max-file-size: 5MB
      max-request-size: 50MB
      location: /E:/temp  #指定临时目录


  #连接redis
  redis:
    host: 10.10.0.152
    port: 6379
    timeout: 5s #超时时间
    lettuce:
      pool:
        max-active: 10 #最大活动数
        max-idle: 8 #最大闲置数
        max-wait: 5ms #最大等待数
        min-idle: 1 #最小闲置数
      shutdown-timeout: 100ms #超时停机时间

#mybatis设置-----------------------
mybatis:
  mapper-locations: classpath:com/libin/mapper/*.xml
  type-aliases-package: com.libin.entities
  executor-type: batch #开启mybatis的批处理


#设置日志等级-----------------------
logging:
  level:
    root: error
    com.libin.dao: debug
    com.libin.service: warn
    com.libin.controller: warn

#文件系统
fdfs:
  tracker-list: pro1:22122,pro2:22122
  # 配置默认缩略图
  thumb-image:
    height: 80
    width: 80






在这里插入图片描述

总结:

使用一个通用的.yml配置文件模板可以简化Spring Boot项目的配置过程,并确保配置的一致性。根据项目需求,您可以在模板的基础上进行定制化的配置,以满足不同的业务需求。

参考资料:

  1. “Common Application properties” in Spring Boot documentation: 链接
  2. “Spring Boot in Action” by Craig Walls, Manning Publications, 2020.
  3. “Mastering Spring Boot 2.5” by K. Siva Prasad Reddy, Packt Publishing, 2021.

在这里插入图片描述

原创声明

======= ·

  • 原创作者: 猫头虎

作者wx: [ libin9iOak ]

学习复习

本文为原创文章,版权归作者所有。未经许可,禁止转载、复制或引用。

作者保证信息真实可靠,但不对准确性和完整性承担责任

未经许可,禁止商业用途。

如有疑问或建议,请联系作者。

感谢您的支持与尊重。

点击下方名片,加入IT技术核心学习团队。一起探索科技的未来,共同成长。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

猫头虎

一分也是爱,打赏博主成就未来!

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

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

打赏作者

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

抵扣说明:

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

余额充值