Skip to main content

多环境配置

1. 使用方式​

通过jvm参数传入dawdler.profiles.active 例如:

-Ddawdler.profiles.active=uat

以上指定了uat环境的配置文件.

2. 加载顺序​

如果部署的项目中存在有dawdler.profiles.active的配置会优先加载.

例如:

项目中存在session-redis.properties与session-redis-uat.properties两个配置文件,如果启动参数中有设置 -Ddawdler.profiles.active=uat 则读取到的是session-redis-uat.properties.

本地配置文件优先于统一配置中心的配置.

3. 已支持的组件配置文件列表​

配置文件所属模块所在位置支持统一配置中心支持加密备注
client-conf.xmldawdler-clientweb端{classPath}/否否web端请求配置
dawdler-config.ymldawdler-config-centerweb端与服务端{classPath}/否否统一配置中心配置
services-conf.ymldawdler-server服务端{classPath}/否否服务相关配置
zookeeper.propertiesdawdler-discovery-center-zookeeper-coreweb端与服务端{classPath}/是是基于zk实现注册中心配置
consul.propertiesdawdler-discovery-center-consul-coreweb端与服务端{classPath}/是是基于consul实现注册中心配置
identityConfig.propertiesdawdler-client-plug-sessionweb端{classPath}/是是session相关配置
distributed-transactiondawdler-distributed-transaction-core分布式事务的web端与补偿器{classPath}/是是分布式事务配置
distributed-transaction-redisdawdler-distributed-transaction-core分布式事务的web端与补偿器{classPath}/是是分布式事务redis配置
distributed-transaction-rabbitmqdawdler-distributed-transaction-core分布式事务的web端与补偿器{classPath}/是是分布式事务rabbitmq配置

4. 其他组件的配置​

系统中实现的组件配置全部支持多环境配置、统一配置中心、加密、变量替换功能.

如redis、es、rabbitmq、kafka.

public class UserServiceImpl implements UserService {

@EsInjector("myEs")
EsOperator esOperator;

@RabbitInjector("myRabbit")
RabbitProvider rabbitProvider;

@JedisInjector("myJedis")
JedisOperator jedisOperator;

@KafkaInjector("myKafka")
KafkaProvider kafkaProvider;
}

5. 变量替换​

在所有的xml、properties、yml、统一配置中心中都支持变量替换

用yml来举例:

name: "${app.name}"
port: 9090
url: "${API_URL:http://localhost:3000}"
description: "This is ${app.name:DefaultApp} running on port 9090"

变量替换的优先级 System.getProperty > System.getenv

例子中的${app.name} 先从System.getProperty("app.name")中获取 如果获取不到则通过System.getenv("app.name")获取 如果获取不到则为${app.name}.

例子中的${API_URL:http://localhost:3000} 先从System.getProperty("API_URL")中获取 如果获取不到则通过System.getenv("API_URL")获取 如果获取不到则为http://localhost:3000.