diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinder.java b/spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinder.java index 0c66b46c..67195807 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinder.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinder.java @@ -20,7 +20,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.springframework.aop.framework.Advised; import org.springframework.aop.support.AopUtils; import org.springframework.beans.BeansException; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -34,6 +33,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.cloud.util.ProxyUtils; /** * Listens for {@link EnvironmentChangeEvent} and rebinds beans that were bound to the @@ -94,7 +94,7 @@ public class ConfigurationPropertiesRebinder try { Object bean = this.applicationContext.getBean(name); if (AopUtils.isAopProxy(bean)) { - bean = getTargetObject(bean); + bean = ProxyUtils.getTargetObject(bean); } if (bean != null) { this.applicationContext.getAutowireCapableBeanFactory().destroyBean(bean); @@ -115,19 +115,6 @@ public class ConfigurationPropertiesRebinder return false; } - @SuppressWarnings("unchecked") - private static T getTargetObject(Object candidate) { - try { - if (AopUtils.isAopProxy(candidate) && (candidate instanceof Advised)) { - return (T) ((Advised) candidate).getTargetSource().getTarget(); - } - } - catch (Exception ex) { - throw new IllegalStateException("Failed to unwrap proxied object", ex); - } - return (T) candidate; - } - @ManagedAttribute public Set getBeanNames() { return new HashSet(this.beans.getBeanNames()); diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/util/ProxyUtils.java b/spring-cloud-context/src/main/java/org/springframework/cloud/util/ProxyUtils.java new file mode 100644 index 00000000..57549c43 --- /dev/null +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/util/ProxyUtils.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.util; + +import org.springframework.aop.framework.Advised; +import org.springframework.aop.support.AopUtils; + +/** + * @author Ryan Baxter + */ +public class ProxyUtils { + + @SuppressWarnings("unchecked") + public static T getTargetObject(Object candidate) { + try { + if (AopUtils.isAopProxy(candidate) && (candidate instanceof Advised)) { + return (T) ((Advised) candidate).getTargetSource().getTarget(); + } + } + catch (Exception ex) { + throw new IllegalStateException("Failed to unwrap proxied object", ex); + } + return (T) candidate; + } +}