springboot_yml配置, 以及 properties 和yml转换示例
server: port: 8097 session-timeout: 30 tomcat.max-threads: 0 tomcat.uri-encoding: UTF-8 spring: application: name: feedback # 数据库配置 datasource: name: test #url: jdbc:mysql://192.168.0.180:3306/dsdb #url: jdbc:mysql://10.168.4.19:3306/dsdb url: jdbc:mysql://10.168.31.223:3306/dsdb?useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true username: root password: ds2017 # 使用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 # rabbitMq 配置 rabbitmq: host: 10.168.31.223 port: 5672 username: guest password: guest # publisher-confirms: true # cache 配置 cache: jcache: config: classpath:ehcache.xml # redis 配置 redis: #host: 192.168.0.129 #host: 10.168.4.19 host: 10.168.31.222 port: 6379 pool: max-idle: 100 min-idle: 1 max-active: 1000 max-wait: -1 # jmx 配置 jmx: enabled: false # mybatis 配置 mybatis: mapperLocations: classpath*:mapper/*.xml typeAliasesPackage: com.daoshu.**.mapper pagehelper: helperDialect: mysql reasonable: false supportMethodsArguments: true # fdfs 配置 fdfs: soTimeout: 1500 connectTimeout: 600 thumbImage: #缩略图生成参数 width: 150 height: 150 trackerList: #TrackerList参数,支持多个 - 10.168.31.223:22122 # elasticsearch index和type配置 pvd: base: es-server-config: clusterName: elasticsearch clusterNodeList : - http://10.168.31.223:9200 topicIndexName: knife topicIndextype: topic eureka: instance: prefer-ip-address: true status-page-url: http://10.168.31.146:${server.port}/swagger-ui.html client: service-url: defaultZone: http://daoshu:ds2017@10.168.31.222:10000/eureka hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 60000 ribbon: ConnectTimeout: 3000 ReadTimeout: 50000 MaxAutoRetries: 1 MaxAutoRetriesNextServer: 2 OkToRetryOnAllOperations: false
-------------------------------------
下面贴一个,自己项目中 properties和yml两种配置的转换
application.properties
server.port=8080 #mysql spring.datasource.username=root spring.datasource.password=root spring.datasource.url=jdbc:mysql://localhost:3306/exam?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.initialSize=5 //初始化连接数 spring.datasource.minIdle=5 //最大空闲连接 spring.datasource.maxActive=20 //最大连接数量 spring.datasource.maxWait=60000 //最小空闲连接 #mybatis-plus #mybatis mapper文件的位置 mybatis-plus.mapper-locations=classpath*:mapper/*.xml #扫描pojo类的位置,在此处指明扫描实体类的包,在mapper中就可以不用写pojo类的全路径名了 mybatis-plus.type-aliases-package=com.exam.demo.dao mybatis-plus.configuration.mapUnderscoreToCamelCase=true #mybatis.configuration.mapperLocations=classpath:/mapper/*.xml logging.level.com.exam.mapper=debug
application.yml
server: port: 8080 spring: datasource: url: jdbc:mysql://localhost:3306/qj_au?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai username: root password: root driver-class-name: com.mysql.jdbc.Driver platform: mysql type: com.alibaba.druid.pool.DruidDataSource # 下面为连接池的补充设置,应用到上面所有数据源中 # 初始化大小,最小,最大 initialSize: 1 minIdle: 5 maxActive: 20 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: 30000 validationQuery: select ‘x‘ testWhileIdle: true testOnBorrow: false testOnReturn: false # 打开PSCache,并且指定每个连接上PSCache的大小 poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,‘wall‘用于防火墙 filters: stat,wall,slf4j # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 合并多个DruidDataSource的监控数据 #useGlobalDataSourceStat: true mybatis-plus: mapper-locations: classpath*:mapper/*.xml type-aliases-package: com.exam.mapper global-config: id-type: 0 field-strategy: 2 capital-mode: true refresh-mapper: true # 原生配置 configuration: map-underscore-to-camel-case: true cache-enabled: false