Browse Source

DATACMNS-1215 - Fixed repository lookup for proxy domain classes.

We now consistently use the user class for repository (metadata) lookup in Repositories.
pull/271/head
Oliver Gierke 8 years ago
parent
commit
1e5aad94cf
  1. 8
      src/main/java/org/springframework/data/repository/support/Repositories.java
  2. 18
      src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java

8
src/main/java/org/springframework/data/repository/support/Repositories.java

@ -122,7 +122,9 @@ public class Repositories implements Iterable<Class<?>> { @@ -122,7 +122,9 @@ public class Repositories implements Iterable<Class<?>> {
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
return repositoryFactoryInfos.containsKey(domainClass);
Class<?> userClass = ClassUtils.getUserClass(domainClass);
return repositoryFactoryInfos.containsKey(userClass);
}
/**
@ -135,7 +137,9 @@ public class Repositories implements Iterable<Class<?>> { @@ -135,7 +137,9 @@ public class Repositories implements Iterable<Class<?>> {
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
Optional<String> repositoryBeanName = Optional.ofNullable(repositoryBeanNames.get(domainClass));
Class<?> userClass = ClassUtils.getUserClass(domainClass);
Optional<String> repositoryBeanName = Optional.ofNullable(repositoryBeanNames.get(userClass));
return beanFactory.flatMap(it -> repositoryBeanName.map(it::getBean));
}

18
src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java

@ -29,6 +29,7 @@ import org.junit.Before; @@ -29,6 +29,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@ -140,6 +141,23 @@ public class RepositoriesUnitTests { @@ -140,6 +141,23 @@ public class RepositoriesUnitTests {
.hasValueSatisfying(it -> assertThat(it.getRepositoryInterface()).isEqualTo(PersonRepository.class));
}
@Test // DATACMNS-1215
public void exposesRepositoryForProxyType() {
ProxyFactory factory = new ProxyFactory();
factory.setTarget(new Person());
factory.setProxyTargetClass(true);
Object proxy = factory.getProxy();
assertThat(ClassUtils.isCglibProxy(proxy)).isTrue();
Repositories repositories = new Repositories(context);
assertThat(repositories.hasRepositoryFor(proxy.getClass())).isTrue();
assertThat(repositories.getRepositoryFor(proxy.getClass())).isNotEmpty();
}
class Person {}
class Address {}

Loading…
Cancel
Save