|
|
|
@ -37,10 +37,13 @@ import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans
|
|
|
|
|
import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder;
|
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
|
import org.springframework.core.annotation.AnnotationUtils;
|
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.ReflectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import static java.util.Locale.ENGLISH;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Optimize {@link ConfigurationPropertiesRebinder}, only rebuild affected beans.
|
|
|
|
|
*
|
|
|
|
@ -55,6 +58,8 @@ public class AffectedConfigurationPropertiesRebinder extends ConfigurationProper
|
|
|
|
|
|
|
|
|
|
private final Map<String, Map<String, Object>> propertiesBeanDefaultValues = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
static final String SET_PREFIX = "set";
|
|
|
|
|
|
|
|
|
|
public AffectedConfigurationPropertiesRebinder(ConfigurationPropertiesBeans beans) {
|
|
|
|
|
super(beans);
|
|
|
|
|
}
|
|
|
|
@ -137,7 +142,8 @@ public class AffectedConfigurationPropertiesRebinder extends ConfigurationProper
|
|
|
|
|
}
|
|
|
|
|
}, field -> {
|
|
|
|
|
int modifiers = field.getModifiers();
|
|
|
|
|
return !Modifier.isFinal(modifiers) && !Modifier.isStatic(modifiers);
|
|
|
|
|
String setMethodName = SET_PREFIX + capitalize(field.getName());
|
|
|
|
|
return !Modifier.isFinal(modifiers) && !Modifier.isStatic(modifiers) && ClassUtils.hasMethod(field.getDeclaringClass(), setMethodName, field.getType());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ignored) {
|
|
|
|
@ -146,4 +152,11 @@ public class AffectedConfigurationPropertiesRebinder extends ConfigurationProper
|
|
|
|
|
propertiesBeanDefaultValues.put(propertiesBean.getName(), defaultValues);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String capitalize(String name) {
|
|
|
|
|
if (name == null || name.length() == 0) {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
return name.substring(0, 1).toUpperCase(ENGLISH) + name.substring(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|