Merge branch '2.2.x'

This commit is contained in:
Spencer Gibb
2020-03-03 17:55:32 -05:00
7 changed files with 72 additions and 17 deletions

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.autoconfigure;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -140,8 +139,7 @@ public class RefreshAutoConfiguration {
* Class names for beans to post process into refresh scope. Useful when you don't
* control the bean definition (e.g. it came from auto-configuration).
*/
private Set<String> refreshables = new HashSet<>(
Arrays.asList("com.zaxxer.hikari.HikariDataSource"));
private Set<String> refreshables = new HashSet<>();
public Set<String> getRefreshable() {
return this.refreshables;

View File

@@ -35,6 +35,7 @@ import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
/**
* Listens for {@link EnvironmentChangeEvent} and rebinds beans that were bound to the
@@ -96,6 +97,11 @@ public class ConfigurationPropertiesRebinder
bean = ProxyUtils.getTargetObject(bean);
}
if (bean != null) {
// TODO: determine a more general approach to fix this.
// see https://github.com/spring-cloud/spring-cloud-commons/issues/571
if (getNeverRefreshable().contains(bean.getClass().getName())) {
return false; // ignore
}
this.applicationContext.getAutowireCapableBeanFactory()
.destroyBean(bean);
this.applicationContext.getAutowireCapableBeanFactory()
@@ -115,6 +121,14 @@ public class ConfigurationPropertiesRebinder
return false;
}
@ManagedAttribute
public Set<String> getNeverRefreshable() {
String neverRefresh = this.applicationContext.getEnvironment().getProperty(
"spring.cloud.refresh.never-refreshable",
"com.zaxxer.hikari.HikariDataSource");
return StringUtils.commaDelimitedListToSet(neverRefresh);
}
@ManagedAttribute
public Set<String> getBeanNames() {
return new HashSet<>(this.beans.getBeanNames());

View File

@@ -41,6 +41,12 @@
"type": "java.util.Set<java.lang.String>",
"description": "Additional class names for beans to post process into refresh scope.",
"defaultValue": true
},
{
"name": "spring.cloud.refresh.never-refreshable",
"type": "java.lang.String",
"description": "Comma separated list of class names for beans to never be refreshed or rebound.",
"defaultValue": true
}
]
}