1.添加bootstarp.yml配置文件
server:
port: 9090
#nacos注册中心,配置中心
spring:
profiles:
active: dev
application:
name: jin-he-sign
cloud:
nacos:
# 服务发现配置
discovery:
# Nacos服务端ip端口
server-addr: 127.0.0.1:8848
# 命名空间(主要起隔离作用,通常用来区分测试,开发环境下的配置)
namespace: e8d801ca-c6bb-40d8-863b-8ee91b6679ad
# 配置中心
config:
# 开启配置
enabled: true
server-addr: 127.0.0.1:8848
# 配置文件名称(对应Nacos中的data_id,命名规则一般为applicationName+active级别+文件后缀)
name: jin-he-sign-dev
# 文件后缀
file-extension: yaml
namespace: e8d801ca-c6bb-40d8-863b-8ee91b6679ad
# 组id(用来隔离,一般用来区分不同的项目)
group: DEFAULT_GROUP
#
refresh-enabled: true
# ext-config[0]:
# data-id: ext-config-common01.properties
# group: message-ext.properties
# refresh: true
这里config下name属性可配可不配,规则如下:
1.1采用application.name/config.name+后缀名加载,现在之后再加载application.name/config.name+"-"+"配置文件级别(dev,prod)".后缀名;
2.添加maven依赖
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency>
3.再nacos创建配置文件
spring:
redis:
conn-timeout: 30000
database: 1
host: {ip}
max-active: 80
max-idle: 10
max-wait: -1
min-idle: 5
password: {password}
port: 6379
ssl: false
crypto:
key: {加密密钥}
request:
decrypt:
enabled: true
datasource:
druid:
connect-properties:
password: {加密后的密钥}
driver-class-name: com.mysql.jdbc.Driver
filter:
*这里开启druid的stat监控
stat:
enabled: true
log-slow-sql: true
slow-sql-millis: 200
*这里开启druid的sql日志输出
slf4j:
enabled: true
*连接的获取不打印
statement-close-after-log-enabled: false
*连接的归还不打印
statement-prepare-after-log-enabled: false
initial-size: 2
max-active: 10
max-wait: 60000
min-evictable-idle-time-millis: 300000
min-idle: 2
password: gdriver@2020
test-on-borrow: false
test-on-return: false
test-while-idle: true
time-between-eviction-runs-millis: 60000
url: {url}
username: {name}
validation-query: select 1
server:
servlet:
context-path: /e-sign
file:
tmp:
dir: E:\uploadtempdir
mybatis:
mapper-locations: classpath*:mybatis/*.xml
print:
tmp:
dir: C:\Kobe\saaserp\myproject\ui\my-erp-ui\static\print
logging:
config: classpath:logback-spring.xml
refresh 要配合
@RefreshScope 使用
添加再需要读取配置的类上