在Flink中会有很多配置,比如像算子的并行度配置、Kafka 数据源的配置(broker 地址、topic 名、group.id)、Checkpoint 是否开启、状态后端存储路径、数据库地址、用户名和密码等。这些配置肯定不能写死在代码中,需要在配在配置文件中。
先指定环境
可以先配置一个application.properties,里面配置哪个环境,比如
ykc.profile=dev
#ykc.profile=test
#ykc.profile=prod
分别表示读取的是
application-dev.properties、application-test.properties、application-prod.properties的配置文件。
从具体环境的配置文件中读取配置
读取配置文件的工具类
public class PropertiesConstants {
public static String PROPERTIES_FILE_NAME = "/application-dev-location.properties";
static {
// 读取配置文件 application.properties 中的 ykc.profile
String profile=PropConfigUtil.getProperties("ykc.profile");
if(profile.equals("dev-location")){
PROPERTIES_FILE_NAME="/application-dev.properties";
}
if(profile.equals("tes