application.properties 和 applica

2020-05-14  本文已影响0人  ChinaGoodStaff
#application.yml
 
server:
  port: 8086
  
spring:
    datasource:
        name: test
        url: jdbc:mysql://192.168.1.222:3306/test
        username: root
        password: xxx
        # 使用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
#application.properties
 
server.port=8085
 
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
spring.datasource.url=jdbc:mysql://192.168.1.222:3306/test
spring.datasource.username=root
spring.datasource.password=***
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
 
spring.druid.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.druid.datasource.driverClassName=com.mysql.jdbc.Driver
spring.druid.datasource.url=jdbc:mysql://localhost:3306/spring_boot?characterEncoding=utf-8
spring.druid.datasource.username=root
spring.druid.datasource.password=xxx

yml文件的好处是树状结构,一目了然,实质上跟properties是差不多的。

如果你的项目中存在 application.properties 文件,那么 application.yml 文件就只是一个摆设。
1、原有的key,例如spring.datasource.url,按“.”分割,都变成树状的配置
2、key后面的冒号,后面一定要跟一个空格
3、把原有的application.properties删掉。然后一定要执行一下 maven -X clean install

在Spring Boot中多环境配置⽂件名需要满⾜ application-{profile}.yml 的格式,其 中{profile}对应你的环境标识,⽐如:
application-dev.yml :开发环境
application-test.yml :测试环境
application-prod.yml :⽣产环境

application.properties多环境配置同上

上一篇下一篇

猜你喜欢

热点阅读