Springboot的yml配置文件

HikariCP

过滤不加载数据源

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/db01?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
    username: root
    password: root

Druid

spring:
  datasource:
    #引入druid数据源
	#type: com.alibaba.druid.pool.DruidDataSource
	#driver-class-name: com.mysql.jdbc.Driver
	# 或
    druid:
      type: com.alibaba.druid.pool.DruidDataSource
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/db01?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
      username: root
      password: root

Mybatis-plus

mybatis-plus:
  type-aliases-package: com.xx.pojo
  mapper-locations: classpath:/mybatis/mappers/*.xml
  configuration:
  	#驼峰
  	#数据库表列:user_name 
	#实体类属性:userName
    map-underscore-to-camel-case: true

Log4j等级

共8个,建议只用四个,优先级从高到低分别是ERROR、WARN、INFO、DEBUG

logging:
  level: 
    com.xx.mapper: debug

Dubbo

生产端

dubbo:
  scan:
    basePackages: com.xx
  application:
    name: consumer-web   #定义消费者名称
  registry:               #注册中心地址
    address: zookeeper://192.168.126.129:2181?backup=192.168.126.129:2182,192.168.126.129:2183

消费端

dubbo:
  scan:
    basePackages: com.xx    #指定dubbo的包路径
  application:              #应用名称
    name: provider-cart     #一个接口对应一个服务名称
  registry:
    address: zookeeper://192.168.126.129:2181?backup=192.168.126.129:2182,192.168.126.129:2183
  protocol:  #指定协议
    name: dubbo  #使用dubbo协议(tcp-ip)
    port: 20880  #单机每一个服务都有自己特定的端口 不能重复.

SpringMVC视图解析器

spring:     #定义springmvc视图解析器
  mvc:
    view:
      prefix: /WEB-INF/views/
      suffix: .html

在这里插入图片描述

Thymeleaf

spring:
   thymeleaf:
      cache: false
      prefix: classpath:/templates/pages/

暴露监控监控

management:
	endpoints:
		web:
			exposure:
				include=*

异步线程池

spring:
	task:
    	execution:
      		pool:
        		core-size: 8
        		max-size: 256
        		keep-alive: 60s
        		queue-capacity: 256
      		thread-name-prefix: db-service-thread-
参数解释:
queue-capacity: 队列长度
core-size: 核心线程数
max-size: 128 最大线程数
keep-alive: 60s 默认允许空闲时间60秒
thread-name-prefix: 线程前缀名称,名字取得较长便于测试识别
过程解释:
1.如果当前线程池的线程数还没有达到核心线程数大小,即 poolSize < corePoolSize ,无论是否有空闲的线程,系统回新增一个线程来处理新提交的任务;
2.如果当前线程池的线程数大于或者等于核心线程数大小,即 poolSize >= corePoolSize,且任务队列未满时,将提交的任务提交到阻塞队列中,等待处理
3.如果当前线程池的线程数大于或者等于核心线程数大小,即 poolSize >= corePoolSize,且任务队列已满时,分以下两种情况:
   1.poolSize < maximumPoolSize ,新增线程来处理任务;
   2.poolSize = maximuxPoolSize ,线程池的处理能力已达极限,此时会拒绝增加新任务,如何拒绝取决于RejectedExecutionHandler

properties文件使用

redis.properties文件在resource目录下

redis.host=192.168.126.129
redis.port=6379
#配置分片
#redis.nodes=192.168.126.129:6379,192.168.126.129:6380,192.168.126.129:6381
#哨兵
#redis.sentinel=192.168.126.129:26379
#集群
redis.nodes=192.168.126.129:7000,192.168.126.129:7001,192.168.126.129:7002,192.168.126.129:7003,192.168.126.129:7004,192.168.126.129:7005

使用

@PropertySource("classpath:/reids.properties")
public class RedisConfigure {
	@Value("${redis.nodes}")
    private String nodes;
}

多环境拆分选择

#指定使用某个分割的配置
spring:
  profiles:
    active: prod
---
#新版本写法
#spring:
#  profiles: dev 是2.4版本以下写法
spring:
  config:
    activate:
     on-profile: dev #当前生产环境配置名称

server:
  port: 80   #定义端口号

redis:
  host: 127.0.0.1
  port: 6379

--- # --- 实现文件环境拆分
spring:
  config:
    activate:
      on-profile: prod  #当前生产环境配置名称

server:
  port: 8080

redis:
  host: 10.0.0.1
  port: 6276
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可——叹——落叶飘零

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值