base包常量类设置公共变量,常量
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* <Description>
*
* @author CJJ
* @version 1.0
* @createDate 2019/09/06 18:02
*
*/
@Component
public class KylinConstant {
public KylinConstant kylinConstant;
public static final String MYSQL = "mysql";
public static final String KYLIN = "kylin";
public static final String QUERY = "/kylin/api/query";
public static final String DB_TYPE = "kylin";
public static String KYLIN_URL;
public static final String ApiModels = "/kylin/api/models";
public static final String ApiCubes = "/kylin/api/cubes";
public static final String API_CUBE_DESC = "/kylin/api/cube_desc/";
public static String Basic_Auth;
public static String Media_Type = "application/json";
public static final String ApiTables = "/kylin/api/tables";
public static String ProjectName;
@PostConstruct
public void init() {
kylinConstant = this;
KYLIN_URL = kylinConstant.kylinUrl;
Basic_Auth = kylinConstant.basicAuth;
ProjectName = kylinConstant.projectName;
}
@Value("${kylin.url}")
public String kylinUrl;
@Value(("${kylin.basic_auth}"))
public String basicAuth;
@Value("${kylin.project}")
public String projectName;
}
然后在引用base包的模块配置nacos,然后添加配置
spring:
application:
name: xxxx
cloud:
nacos:
config:
server-addr: 10.1.24.193:8848
file-extension: yaml
ext-config:#配置公共配置列表
-
dataId: base-dev.yaml
group: DEFAULT_GROUP
refresh: true
profiles:
active: dev
直接使用@Value可以使用Nacos中的配置,不知道是不是版本问题,文档给的是@NacosValue
使用公共模块,不需要多次创建对象