filter set method

pull/699/head
dongyinuo 3 years ago
parent 281b6b7835
commit 919ca57c34

@ -37,10 +37,13 @@ import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans
import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder; import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import static java.util.Locale.ENGLISH;
/** /**
* Optimize {@link ConfigurationPropertiesRebinder}, only rebuild affected beans. * 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<>(); private final Map<String, Map<String, Object>> propertiesBeanDefaultValues = new ConcurrentHashMap<>();
static final String SET_PREFIX = "set";
public AffectedConfigurationPropertiesRebinder(ConfigurationPropertiesBeans beans) { public AffectedConfigurationPropertiesRebinder(ConfigurationPropertiesBeans beans) {
super(beans); super(beans);
} }
@ -137,7 +142,8 @@ public class AffectedConfigurationPropertiesRebinder extends ConfigurationProper
} }
}, field -> { }, field -> {
int modifiers = field.getModifiers(); 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) { catch (Exception ignored) {
@ -146,4 +152,11 @@ public class AffectedConfigurationPropertiesRebinder extends ConfigurationProper
propertiesBeanDefaultValues.put(propertiesBean.getName(), defaultValues); 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);
}
} }

Loading…
Cancel
Save