Application.yml 常用配置

Tomcat配置

server:
  port: 8081  #设置请求端口
  servlet:
    context-path: /spring-boot-demo  #指定 Tomcat的请求路径 http://localhost:8081/spring-boot-demo/+ 地址
    encoding:
      charset: UTF-8    #设置 Tomcat 编码格式

数据源配置

spring:
  datasource:
    #mysql的配置加载驱动类信息
    driver-class-name: com.mysql.cj.jdbc.Driver
    #mysql的连接信息
    url: jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone = GMT
    #用户名
    username: root
    #密码
    password: 123456
    # Type 设置使用何种类型的数据库连接池
    type: com.alibaba.druid.pool.DruidDataSource 
    # c3p0连接池  com.mchange.v2.c3p0.ComboPooledDataSource

  #redis配置
  redis:
    database: 0       #几号数据库
    host: 127.0.0.1   # Redis服务器地址
    port: 6379        # Redis服务器连接端口
    password:		  # Redis服务器连接密码(默认为空)
    jedis:            #基于java语言的redis客户端,集成了redis 的命令操作,提供了连接池管理。
      pool:
        max-active: 8    # 连接池最大连接数(使用负值表示没有限制)
        max-wait: -1     # 连接池最大阻塞等待时间(使用负值表示没有限制)
        max-idle: 8      # 连接池中的最大空闲连接
        min-idle: 0      # 连接池中的最小空闲连接
        timeout: 2000ms  # 连接超时时间(毫秒)默认是2000ms

Mybatis 配置

mybatis:
  #加载 mapper.xml 文件到容器中
  mapper-locations: classpath:mapper/*.xml 
  # 别名,简化 mapper.xml 中请求响应参数类型
  type-aliases-package: com.zhuzhu.springboot.pojo  
  configuration:
  #开启驼峰映射
  map-underscore-to-camel-case: true
  # sql日志的打印
  log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

日志打印配置

logging:
  level:
    com.zhuzhu.springboot:
          #指定打印对应文件夹的日志,并设置打印的日志的级别 (com.zhuzhu.springboot.mapper 包)
          mapper: debug 
  file:
    #指定日志文件生成的位置
    name: D:/spring.log 

设置静态资源的路径(spring:resources下的)

(默认的是classpath:/static,classpath:/public,classpath:/resources,classpath:/META-INF/resource)

  resources:
      static-locations: ["classpath:/static/", "classpath:/public/","classpath:/mapper/"]
      

thymeleaf的模板配置

  thymeleaf:
      prefix: classpath:/templates
      mode: HTML
      cache: false
      encoding: UTF-8
      #     新版本不支持content-type: text/html,故新写法
      servlet:
        content-type: text/html
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐