springboot 配置文件拆分

yml 配置文件

application.yml

application.yml 配置公共的参数

#整合mybatis
mybatis:
  mapper-locations: classpath:mapper/*MapperExt.xml,classpath:mapper/*Mapper.xml
  type-aliases-package: com.cmiot.datamanage.entity
#pagehelper配置
pagehelper:
  helperDialect: mysql
  offsetAsPageNum: true
  rowBoundsWithCount: true
  pageSizeZero: true
  reasonable: false
  params: pageNum=pageHelperStart;pageSize=pageHelperRows;
  supportMethodsArguments: true
#日志+开启sql打印
logging:
  config: classpath:logback-spring.xml
  level:
    com.cmiot.airwrite.dao.idao: DEBUG
    com.didispace: DEBUG
    com.cmiot.airwrite: debug
uploadFilePathUser: usr/writeTemp
server:
  port: 8088
  ssl:
    key-store: classpath:keystore.p12
    key-alias: tomcat
    enabled: true
    key-store-type: PKCS12
    key-store-password: 123456
spring:
  profiles:
    active: @activatedProperties@


application-dev.yml

application-dev.yml 配置开发环境独有的参数

#数据库配置
spring :
#  配置上传文件最大   但是目前并不行
  #  servlet:
  #    multipart:
  #      enabled: true
  #      resolve-lazily: true
  #      max-file-size: 50MB
  #      max-request-size : 50MB
  datasource :
    name: druidDataSource
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      driver-class-name: com.mysql.jdbc.Driver
      #      ?为何需要配置时区
      url: jdbc:mysql://localhost:3306/air_write_card?useUnicode=true&characterEncoding=utf8&useTimezone=true&serverTimezone=GMT%2B8
      username: root
      password: 123456
      filters: stat,wall,log4j,config
      max-active: 100
      initial-size: 1
      max-wait: 60000
      min-idle: 1
      time-between-eviction-runs-millis: 60000
      min-evictable-idle-time-millis: 300000
      validation-query: select 'x'
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      pool-prepared-statements: true
      max-open-prepared-statements: 50
      max-pool-prepared-statement-per-connection-size: 20

application-prod.yml

application-prod.yml 配置生产环境独有的参数

#数据库配置
spring :
#  配置上传文件最大   但是目前并不行
  #  servlet:
  #    multipart:
  #      enabled: true
  #      resolve-lazily: true
  #      max-file-size: 50MB
  #      max-request-size : 50MB
  datasource :
    name: druidDataSource
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      driver-class-name: com.mysql.jdbc.Driver
      #      ?为何需要配置时区
      url: jdbc:mysql://39.105.218.249:3306/air_write_card?useUnicode=true&characterEncoding=utf8&useTimezone=true&serverTimezone=GMT%2B8
      username: root
      password: 123456
      filters: stat,wall,log4j,config
      max-active: 100
      initial-size: 1
      max-wait: 60000
      min-idle: 1
      time-between-eviction-runs-millis: 60000
      min-evictable-idle-time-millis: 300000
      validation-query: select 'x'
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      pool-prepared-statements: true
      max-open-prepared-statements: 50
      max-pool-prepared-statement-per-connection-size: 20

application-test.yml

application-test.yml 配置测试环境独有的参数

#数据库配置
spring :
#  配置上传文件最大   但是目前并不行
  #  servlet:
  #    multipart:
  #      enabled: true
  #      resolve-lazily: true
  #      max-file-size: 50MB
  #      max-request-size : 50MB
  datasource :
    name: druidDataSource
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      driver-class-name: com.mysql.jdbc.Driver
      #      ?为何需要配置时区
      url: jdbc:mysql://192.168.218.249:3306/air_write_card?useUnicode=true&characterEncoding=utf8&useTimezone=true&serverTimezone=GMT%2B8
      username: root
      password: 123456
      filters: stat,wall,log4j,config
      max-active: 100
      initial-size: 1
      max-wait: 60000
      min-idle: 1
      time-between-eviction-runs-millis: 60000
      min-evictable-idle-time-millis: 300000
      validation-query: select 'x'
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      pool-prepared-statements: true
      max-open-prepared-statements: 50
      max-pool-prepared-statement-per-connection-size: 20

pom.xml

在 pom.xml 指定使用的配置

    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <activatedProperties>dev</activatedProperties>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <activatedProperties>test</activatedProperties>
            </properties>

        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <activatedProperties>prod</activatedProperties>
            </properties>
        </profile>
    </profiles>

properties 配置文件

application.properties

application.properties 配置公共的参数

server.port=9200
spring.application.name=devops
#eureka.client.service-url.defaultZone=http://icot-eureka:8001/eureka/
eureka.client.service-url.defaultZone=http://localhost:8001/eureka/
eureka.instance.instance-id=${spring.application.name}-instance-${random.value}
eureka.instance.prefer-ip-address=true
spring.profiles.active=@activatedProperties@
# mybatis自动驼峰转换
mybatis.configuration.mapUnderscoreToCamelCase=true


#pagehelper分页插件配置
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

feign.hystrix.enabled=true
hystrix.threadpool.default.coreSize=10
hystrix.command.default.fallback.enabled=true

# 此条配置要加上否则报Unable to connect to Command Metric Stream 异常
management.endpoints.web.exposure.include=hystrix.stream

hystrix.command.default.execution.timeout.enabled=true
#断路器的超时时间,下级服务返回超出熔断器时间,即便成功,消费端消息也是TIMEOUT,所以一般断路器的超时时间需要大于ribbon的超时时间。
#服务的返回时间大于ribbon的超时时间,会触发重试
##默认=1000,太小
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=8000

#断路器详细设置
#当在配置时间窗口内达到此数量的失败后,进行短路。默认20个)
hystrix.command.default.circuitBreaker.requestVolumeThreshold=20
#短路多久以后开始尝试是否恢复,默认5s)
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds=5
#出错百分比阈值,当达到此阈值后,开始短路。默认50%)
hystrix.command.default.circuitBreaker.errorThresholdPercentage=50%
#ribbon请求连接的超时时间- 限制3秒内必须请求到服务,并不限制服务处理的返回时间
ribbon.ConnectTimeout=3000
#请求处理的超时时间 下级服务响应最大时间,超出时间消费方(路由也是消费方)返回timeout
ribbon.ReadTimeout=5000

application-dev.properties

application-dev.properties 配置开发环境独有的参数

# mysql config
spring.datasource.url=jdbc:mysql://192.168.1.30:3306/idp_devops?serverTimezone=Asia/Shanghai
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.username=idp
spring.datasource.password=icot.com

# REDIS (RedisProperties)
# Redis数据库索引(默认为0)
spring.redis.database=2
# Redis服务器地址
spring.redis.host=192.168.1.30
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=icot.com

application-prod.properties

application-prod.properties 配置生产环境独有的参数

application-test.properties

application-test.properties 配置测试环境独有的参数

# mysql config
spring.datasource.url=jdbc:mysql://rm-bp129953guuzs4d32.mysql.rds.aliyuncs.com:3306/idp_devops
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.username=icot_idp_test
spring.datasource.password=icot@123

# REDIS (RedisProperties)
# Redis数据库索引(默认为0)
spring.redis.database=1
# Redis服务器地址
spring.redis.host=icot.com
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=icot@123

pom.xml

在 pom.xml 指定使用的配置

    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <activatedProperties>dev</activatedProperties>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <activatedProperties>test</activatedProperties>
            </properties>

        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <activatedProperties>prod</activatedProperties>
            </properties>
        </profile>
    </profiles>

项目启动

启动时不用做其它配置,正常启动即可。