Spring-Boot配置不同環境的yml配置檔案
阿新 • • 發佈:2019-02-20
Spring Boot專案開發部署過程中,通常會有多套環境(開發dev、測試test、預生產rc,生產pro),每套環境的配置是不同的。將所有環境共同的引數配置在同一個檔案中;再將每套環境不同的引數配置在各自檔案中,可以減少部署錯誤的概率,同時專案可讀性好,也便於維護。
application.yml 配置共同的引數,並確定當前執行環境
debug: false mybatis: mapper-locations: classpath:mapping/*.xml type-aliases-package: com.fhbean.springboot.mybatisdemo.model #pagehelper分頁外掛 pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql spring: profiles: active: dev
這裡的spring.profiles.active=dev即表示,當前是dev環境;application-{profile}.yml就對應application-dev.yml,{profile}的取值可以是dev, test, rc, pro
application-dev.yml
server: port: 8080 spring: profiles: dev datasource: name: test url: jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true username: root password: root # 使用druid資料來源 type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20