Spring Boot 的配置文件有哪几种格式?它们有什么区别?

.properties 和 .yml,它们的区别主要是书写格式不同。

application.properties案例:

server.port=8084
spring.datasource.url=jdbc:mysql://localhost:3306/personalmall?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root
#连接池初始化大小
spring.datasource.druid.initial-size=5
#最小空闲连接数
spring.datasource.druid.min-idle=10
#最大连接数
spring.datasource.druid.max-active=20
#不统计这些请求数据
spring.datasource.druid.web-stat-filter.exclusions="*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
#访问监控网页的登录用户名和密码
spring.datasource.druid.stat-view-servlet.login-username=druid
spring.datasource.druid.stat-view-servlet.login-password=druid
#默认为stat,即开启sql监控。这里加了个wall,表示同时开启sql防火墙
spring.datasource.druid.filters=stat,wall
#spring监控,com.javaliao.poral是我的控制层包名,也可以是服务层,用逗号分隔多个监控内容
spring.datasource.druid.aop-patterns=com.javaliao.poral.controller.*
#监控页面登录用户名
spring.datasource.druid.StatViewServlet.loginUsername=admin
#监控页面登录密码
spring.datasource.druid.StatViewServlet.loginPassword=admin
#mybatis配置
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.mapper-locations=classpath:dao/*Dao.xml,classpath:mapper/*Mapper.xml
#thymeleaf配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
#日志配置DEBUG,INFO,WARN,ERROR
logging.level.root: info 
# 打印sql到控制台
logging.level.com.javaliao.poral.mapper : debug
#自定义的sql
logging.level.com.javaliao.poral.dao : debug

application.yml案例:

server:
  port: 8001
spring:
  thymeleaf:
    prefix: classpath:/templates/
    mode: LEGACYHTML5
    cache:  false
  mvc:
    view:
      prefix: classpath:/templates/
      suffix: .html
    static-path-pattern: classpath:/static/,classpath:/templates/
  resources:
    static-locations: classpath:/resources/,classpath:/templates/,classpath:/static/
  datasource:
    url: jdbc:mysql://localhost:3306/personalmall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    username: root
    password: root
    druid:
      initial-size: 5 #连接池初始化大小
      min-idle: 10 #最小空闲连接数
      max-active: 20 #最大连接数
      web-stat-filter:
        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据
      stat-view-servlet: #访问监控网页的登录用户名和密码
        login-username: druid
        login-password: druid

# 打印sql
logging:
  level:
    com.java.lzw.poral.dao : debug

 

你可能感兴趣的:(框架)