Skip to content

Commit

Permalink
Fixes #2162
Browse files Browse the repository at this point in the history
For cases like #2162, there are other property source wrappers like jasypt, so we won't be able to decide whether to trigger this change or not.
So it's better just to trigger it as it is idempotent.
  • Loading branch information
nobodyiam committed Apr 27, 2019
1 parent 05a3229 commit b8a7ead
Showing 1 changed file with 1 addition and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,13 @@ public void onChange(ConfigChangeEvent changeEvent) {
continue;
}

// 2. check whether the value is really changed or not (since spring property sources have hierarchies)
if (!shouldTriggerAutoUpdate(changeEvent, key)) {
continue;
}

// 3. update the value
// 2. update the value
for (SpringValue val : targetValues) {
updateSpringValue(val);
}
}
}

/**
* Check whether we should trigger the auto update or not.
* <br />
* For added or modified keys, we should trigger auto update if the current value in Spring equals to the new value.
* <br />
* For deleted keys, we will trigger auto update anyway.
*/
private boolean shouldTriggerAutoUpdate(ConfigChangeEvent changeEvent, String changedKey) {
ConfigChange configChange = changeEvent.getChange(changedKey);

if (configChange.getChangeType() == PropertyChangeType.DELETED) {
return true;
}

return Objects.equals(environment.getProperty(changedKey), configChange.getNewValue());
}

private void updateSpringValue(SpringValue springValue) {
try {
Object value = resolvePropertyValue(springValue);
Expand Down

0 comments on commit b8a7ead

Please sign in to comment.