spring cloud 配置文件:
新建 Spring Boot 项目,引入 config-server 和 starter-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- spring cloud config 服务端包 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
通过nacos配置
bootstrap.yml 文件
spring:
profiles:
active: dev #配置文件
application:
name: basic # 应用名称
bootstrap-dev文件
spring:
cloud:
nacos:
discovery:
server-addr: ${NACOS_HOST:10.0.0.0}:${NACOS_PORT:32000} #nacos ip:post
namespace: ${NACOS_NAMESPACE:dev} #配置文件区间
config:
prefix: ${spring.application.name} #nacos上配置文件名
server-addr: ${NACOS_HOST:10.0.0.0}:${NACOS_PORT:32000}
file-extension: yml #nacos上配置文件后缀, 和prefix组合成完整的配置文件名称(basic.yml)
namespace: ${NACOS_NAMESPACE:dev}
shared-configs: common.yml #共用配置文件
nacos : basic.yml文件
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://10.0.0.0:35000/mysql_data?characterEncoding=UTF-8&useUnicode=true&useSSL=false&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
username: root
password: 123456
hikari:
max-lifetime: 500000 #连接池存活事件,默认1800000即30分钟,0表示存活时间无限大,不等于0且小于30秒则会被重置回30分钟
nacos : common.yml文件
server:
port: ${random.int[32768,32999]} #服务端口号区间
undertow:
accesslog:
# 是否启动日志
enabled: true
# Undertow 日志存放目录
dir: ./logs/${spring.application.name}/undertow/
buffer-size: 1024
direct-buffers: true
threads:
io: 16
worker: 256
logging:
file:
name: ./logs/${spring.application.name}/log.log
# 应用监控
management:
endpoints:
web:
exposure:
include: '*'
# openFeign公共配置
feign:
httpclient:
enabled: false
sentinel:
enabled: true
okhttp:
enabled: true
compression:
request:
enabled: true
response:
enabled: true
client:
config:
default:
connect-timeout: 10000 #建立连接超时时长
read-timeout: 10000 #读取超时时长
# spring 配置
spring:
cloud:
config:
# 相同参数,本地优先
override-none: true
# 消息队列配置
rabbitmq:
host: 10.0.0.0
port: 32250
username: admin
password: 123456
# redis配置
redis:
host: 10.0.0.0
port: 32300
database: 0
password: 123456
lettuce:
pool:
max-active: 300 #最大连接数
sleuth:
sampler:
probability: 1.0
mvc:
throw-exception-if-no-handler-found: true
jackson:
time-zone: GMT+8
servlet:
multipart:
# 单个请求最大值
max-request-size: 50MB
# 单个文件最大值
max-file-size: 500MB
版权声明:本文为weixin_51009861原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。