Browse Source

Merge remote-tracking branch 'origin/2.2.x'

pull/985/head
Olga MaciaszekSharma 3 years ago
parent
commit
a23bdb8845
  1. 9
      spring-cloud-context/src/main/java/org/springframework/cloud/util/ProxyUtils.java

9
spring-cloud-context/src/main/java/org/springframework/cloud/util/ProxyUtils.java

@ -18,6 +18,7 @@ package org.springframework.cloud.util;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.util.Assert;
/** /**
* @author Ryan Baxter * @author Ryan Baxter
@ -30,9 +31,13 @@ public final class ProxyUtils {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T getTargetObject(Object candidate) { public static <T> T getTargetObject(Object candidate) {
Assert.notNull(candidate, "Candidate must not be null");
try { try {
if (AopUtils.isAopProxy(candidate) && (candidate instanceof Advised)) { if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) {
return (T) ((Advised) candidate).getTargetSource().getTarget(); Object target = ((Advised) candidate).getTargetSource().getTarget();
if (target != null) {
return (T) getTargetObject(target);
}
} }
} }
catch (Exception ex) { catch (Exception ex) {

Loading…
Cancel
Save