DATAJPA-871 - CrudMethodMetadataPostProcessor now uses the bean ClassLoader.

The thread-local proxy for the CrudMethodMetadata is now created using the bean ClassLoader, which the repository factory gets set from the container.

Renamed the property for the post processor and its lookup method.
This commit is contained in:
Oliver Gierke
2015-11-05 18:53:32 +01:00
parent d26833b7ad
commit b3324a0e7d
3 changed files with 47 additions and 8 deletions

View File

@@ -31,6 +31,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.aop.framework.Advised;
import org.springframework.core.OverridingClassLoader;
import org.springframework.data.jpa.domain.sample.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.custom.CustomGenericJpaRepositoryFactory;
@@ -38,7 +39,9 @@ import org.springframework.data.jpa.repository.custom.UserCustomExtendedReposito
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ClassUtils;
/**
* Unit test for {@code JpaRepositoryFactory}.
@@ -164,6 +167,20 @@ public class JpaRepositoryFactoryUnitTests {
assertEquals(CustomJpaRepository.class, ((Advised) repository).getTargetClass());
}
/**
* @see DATAJPA-819
*/
@Test
public void crudMethodMetadataPostProcessorUsesBeanClassLoader() {
ClassLoader classLoader = new OverridingClassLoader(ClassUtils.getDefaultClassLoader());
factory.setBeanClassLoader(classLoader);
Object processor = ReflectionTestUtils.getField(factory, "crudMethodMetadataPostProcessor");
assertThat(ReflectionTestUtils.getField(processor, "classLoader"), is((Object) classLoader));
}
private interface SimpleSampleRepository extends JpaRepository<User, Integer> {
@Transactional