Springboot application.yml configuration file split

Although a lot of configuration is reduced by using Springboot, some configurations still require a lot of manual operation, and the configuration file in YML format is more intuitive when there is less configuration, but it is not very good when there is more configuration, so split the configuration The file is very necessary, and it is relatively simple to split the configuration file.

# application.yml 文件
spring:
  profiles:
    include:
      - sharding
      - kanyun

Introduce other configuration files through spring.profiles.include in the main configuration file

# application-sharding.yml
spring:
  shardingsphere:
    datasource:
      names: dms
      dms:
        type: com.zaxxer.hikari.HikariDataSource
        jdbc-url: jdbc:mysql://localhost:3306/rds_mysql_1352zk
        username: root
        password: root
    sharding:
      tables:
        t_user:
          actual-data-nodes: dms.t_user_$->{1..2}
          table-strategy:
            inline:
              sharding-column: id
              algorithm-expression: t_user_$->{id % 2 + 1}

            key-generator:
              column: id
              type: SIMPLE
    enabled: true
    props:
      sql:
        show: true
# application-kanyun.properties
banner.location=banner.txt  #可以自定义输出信息的位置
banner.charset=utf-8  #指定编码格式
spring.main.banner-mode=console

It should be noted here that if the wrong file name is included in the main configuration file application.yml, the error that the file cannot be found will not be reported, unless the key configuration information cannot be found and an error will be reported. It should be noted that include can not only import YML files, but also import properties files, and the configuration is also effective. In this way, the format of the configuration file can be customized. After all, some configurations are more convenient to use properties files

Guess you like

Origin blog.csdn.net/kanyun123/article/details/107809455