DATACMNS-1341 - ProxyUtils now detects JDK proxy target classes.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user