当前位置:   article > 正文

Java 4-6、优化启动配置,properties改为yml_java根据环境启动切换yml文件

java根据环境启动切换yml文件

优化启动配置,properties改为yml

yml缩进严格
把之前的配置转换为yml的文件重写一下

一、application.yml


# 环境配置, dev和prod
spring:
  profiles:
    active: dev
  • 1
  • 2
  • 3
  • 4
  • 5

一、application-dev.yml


# 测试服务端口
server:
  port: 1234

  servlet:
    # safari中文乱码问题
    encoding:
      force: true


spring:
  # 关闭模板引擎
  thymeleaf:
    check-template-location: false # 不检查templates目录
    enabled: false # 关闭

  # 数据库配置
  datasource:
    name: test
    url: jdbc:mysql://localhost:3306/a2j?characterEncoding=utf-8
    username: root
    password: 12345678
    driver-class-name: com.mysql.cj.jdbc.Driver

    # 保活时间
    hikari:
      max-lifetime: 500000


# mybatis配置
mybatis:
  # 数据库映射
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.a2j
  configuration:
    map-underscore-to-camel-case: true # 数据库下划线字段转换驼峰
    cache-enabled: false


# logger 日志打印与备份
logging:
  level:
    com.a2j.mapper.*: debug
  config: classpath:log/logback-dev.xml

  # 老的日志打印方式
#  file:
#    name: logs/a2j.log
#  pattern:
#    console: %d %-5level %logger : %msg%n
#    file: %d %-5level [%thread] %logger : %msg%n
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52

一、application-prod.yml


# 正式服务端口
server:
  port: 12345

  servlet:
    # safari中文乱码问题
    encoding:
      force: true


spring:
  # 关闭模板引擎
  thymeleaf:
    check-template-location: false # 不检查templates目录
    enabled: false # 关闭

  # 数据库配置
  datasource:
    name: test
    url: jdbc:mysql://localhost:3306/a2j?characterEncoding=utf-8
    username: root
    password: 12345678
    driver-class-name: com.mysql.cj.jdbc.Driver

    # 保活时间
    hikari:
      max-lifetime: 500000


# mybatis配置
mybatis:
  # 数据库映射
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.a2j
  configuration:
    map-underscore-to-camel-case: true # 数据库下划线字段转换驼峰
    cache-enabled: false


# logger 日志打印与备份
logging:
  level:
    com.a2j.mapper.*: debug
  config: classpath:log/logback-dev.xml

  # 老的日志打印方式
#  file:
#    name: logs/a2j.log
#  pattern:
#    console: %d %-5level %logger : %msg%n
#    file: %d %-5level [%thread] %logger : %msg%n
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号