Dubbo2.7详解( 八 )

4)方法1.2,AbstractInterfaceConfig类#refresh()方法
// 刷新XxConfig// 一个XxConfig对象的属性可能是有值的,也可能是没有值的,这时需要从其他位置获取属性值,来进行属性的覆盖// 覆盖的优先级,从大到小为系统变量->配置中心应用配置->配置中心全局配置->注解或xml中定义->dubbo.properties文件// 以ServiceConfig为例,ServiceConfig中包括很多属性 , 比如timeout// 但是在定义一个Service时,如果在注解上没有配置timeout,那么就会其他地方获取timeout的配置// 比如可以从系统变量->配置中心应用配置->配置中心全局配置->注解或xml中定义->dubbo.properties文件// refresh是刷新,将当前ServiceConfig上的set方法所对应的属性更新为优先级最高的值public void refresh() {try {CompositeConfiguration compositeConfiguration = Environment.getInstance().getConfiguration(getPrefix(), getId());// 表示XxConfig对象本身- AbstractConfigConfiguration config = new ConfigConfigurationAdapter(this);//设置顺序,if (Environment.getInstance().isConfigCenterFirst()) {// The sequence would be: SystemConfiguration -> AppExternalConfiguration -> ExternalConfiguration -> AbstractConfig -> PropertiesConfigurationcompositeConfiguration.addConfiguration(4, config);} else {// The sequence would be: SystemConfiguration -> AbstractConfig -> AppExternalConfiguration -> ExternalConfiguration -> PropertiesConfigurationcompositeConfiguration.addConfiguration(2, config);}// loop methods, get override value and set the new value back to method//Method[] methods = getClass().getMethods();for (Method method : methods) {// 是不是setXX()方法if (MethodUtils.isSetter(method)) {// 获取xx配置项的valueString value = https://www.huyubaike.com/biancheng/StringUtils.trim(compositeConfiguration.getString(extractPropertyName(getClass(), method)));// isTypeMatch() is called to avoid duplicate and incorrect update, for example, we have two'setGeneric' methods in ReferenceConfig.if (StringUtils.isNotEmpty(value) && ClassUtils.isTypeMatch(method.getParameterTypes()[0], value)) {method.invoke(this, ClassUtils.convertPrimitive(method.getParameterTypes()[0], value));}// 是不是setParameters()方法} else if (isParametersSetter(method)) {// 获取parameter配置项的valueString value = https://www.huyubaike.com/biancheng/StringUtils.trim(compositeConfiguration.getString(extractPropertyName(getClass(), method)));if (StringUtils.isNotEmpty(value)) {Map map = invokeGetParameters(getClass(), this);map = map == null ? new HashMap<>() : map;

推荐阅读