DATACMNS-1341 - ProxyUtils now detects JDK proxy target classes.

This commit is contained in:
Oliver Gierke
2018-06-14 11:50:58 +02:00
parent f03ee7fd34
commit 37ab0a5d8f
2 changed files with 17 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ import lombok.experimental.UtilityClass;
import java.util.List;
import java.util.Map;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -75,7 +76,7 @@ public class ProxyUtils {
Assert.notNull(source, "Source object must not be null!");
return getUserClass(source.getClass());
return getUserClass(AopUtils.getTargetClass(source));
}
/**

View File

@@ -17,6 +17,8 @@ package org.springframework.data.util;
import static org.assertj.core.api.Assertions.*;
import java.io.Serializable;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.data.util.ProxyUtils.ProxyDetector;
@@ -50,6 +52,17 @@ public class ProxyUtilsUnitTests {
assertThat(ProxyUtils.getUserClass(proxy)).isEqualTo(UserType.class);
}
@Test // DATACMNS-1341
public void detectsTargetTypeOfJdkProxy() {
ProxyFactory factory = new ProxyFactory();
factory.setTarget(new SomeTypeWithInterface());
factory.setInterfaces(Serializable.class);
Object proxy = factory.getProxy();
assertThat(ProxyUtils.getUserClass(proxy)).isEqualTo(SomeTypeWithInterface.class);
}
static class SampleProxyDetector implements ProxyDetector {
/*
@@ -67,4 +80,6 @@ public class ProxyUtilsUnitTests {
static class UserType {}
static class AnotherSample {}
static class SomeTypeWithInterface implements Serializable {}
}