Browse Source

DATACMNS-1263 - Allow configuration inspection-classloader customization.

We now allow customizing the configuration inspection-classloader with RepositoryConfigurationExtensionSupport.getConfigurationInspectionClassLoader(…). Subclasses may override this method if a customized/isolated classloader is required.

Original pull request: #276.
pull/274/head
Mark Paluch 8 years ago committed by Oliver Gierke
parent
commit
f827ec705e
No known key found for this signature in database
GPG Key ID: 6E42B5787543F690
  1. 23
      src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java

23
src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java

@ -87,7 +87,8 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit @@ -87,7 +87,8 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
for (BeanDefinition candidate : configSource.getCandidates(loader)) {
RepositoryConfiguration<T> configuration = getRepositoryConfiguration(candidate, configSource);
Class<?> repositoryInterface = loadRepositoryInterface(configuration, loader);
Class<?> repositoryInterface = loadRepositoryInterface(configuration,
getConfigurationInspectionClassLoader(loader));
if (repositoryInterface == null) {
result.add(configuration);
@ -113,6 +114,19 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit @@ -113,6 +114,19 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
return result;
}
/**
* Returns the {@link ClassLoader} to load repository interfaces for configuration inspection. Subclasses may override
* this method to provide a customized class loader.
*
* @param loader must not be {@literal null}.
* @return the {@link ClassLoader} for repository interfaces configuration inspection.
* @since 2.1
*/
@Nullable
protected ClassLoader getConfigurationInspectionClassLoader(ResourceLoader loader) {
return loader.getClassLoader();
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getDefaultNamedQueryLocation()
@ -297,17 +311,16 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit @@ -297,17 +311,16 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
/**
* Loads the repository interface contained in the given {@link RepositoryConfiguration} using the given
* {@link ResourceLoader}.
* {@link ClassLoader}.
*
* @param configuration must not be {@literal null}.
* @param loader must not be {@literal null}.
* @param classLoader must not be {@literal null}.
* @return the repository interface or {@literal null} if it can't be loaded.
*/
@Nullable
private Class<?> loadRepositoryInterface(RepositoryConfiguration<?> configuration, ResourceLoader loader) {
private Class<?> loadRepositoryInterface(RepositoryConfiguration<?> configuration, ClassLoader classLoader) {
String repositoryInterface = configuration.getRepositoryInterface();
ClassLoader classLoader = loader.getClassLoader();
try {
return org.springframework.util.ClassUtils.forName(repositoryInterface, classLoader);

Loading…
Cancel
Save