Skip to content

Commit f827ec7

Browse files
mp911deodrotbohm
authored andcommitted
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.
1 parent 8fb5e78 commit f827ec7

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public <T extends RepositoryConfigurationSource> Collection<RepositoryConfigurat
8787
for (BeanDefinition candidate : configSource.getCandidates(loader)) {
8888

8989
RepositoryConfiguration<T> configuration = getRepositoryConfiguration(candidate, configSource);
90-
Class<?> repositoryInterface = loadRepositoryInterface(configuration, loader);
90+
Class<?> repositoryInterface = loadRepositoryInterface(configuration,
91+
getConfigurationInspectionClassLoader(loader));
9192

9293
if (repositoryInterface == null) {
9394
result.add(configuration);
@@ -113,6 +114,19 @@ public <T extends RepositoryConfigurationSource> Collection<RepositoryConfigurat
113114
return result;
114115
}
115116

117+
/**
118+
* Returns the {@link ClassLoader} to load repository interfaces for configuration inspection. Subclasses may override
119+
* this method to provide a customized class loader.
120+
*
121+
* @param loader must not be {@literal null}.
122+
* @return the {@link ClassLoader} for repository interfaces configuration inspection.
123+
* @since 2.1
124+
*/
125+
@Nullable
126+
protected ClassLoader getConfigurationInspectionClassLoader(ResourceLoader loader) {
127+
return loader.getClassLoader();
128+
}
129+
116130
/*
117131
* (non-Javadoc)
118132
* @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getDefaultNamedQueryLocation()
@@ -297,17 +311,16 @@ protected boolean useRepositoryConfiguration(RepositoryMetadata metadata) {
297311

298312
/**
299313
* Loads the repository interface contained in the given {@link RepositoryConfiguration} using the given
300-
* {@link ResourceLoader}.
314+
* {@link ClassLoader}.
301315
*
302316
* @param configuration must not be {@literal null}.
303-
* @param loader must not be {@literal null}.
317+
* @param classLoader must not be {@literal null}.
304318
* @return the repository interface or {@literal null} if it can't be loaded.
305319
*/
306320
@Nullable
307-
private Class<?> loadRepositoryInterface(RepositoryConfiguration<?> configuration, ResourceLoader loader) {
321+
private Class<?> loadRepositoryInterface(RepositoryConfiguration<?> configuration, ClassLoader classLoader) {
308322

309323
String repositoryInterface = configuration.getRepositoryInterface();
310-
ClassLoader classLoader = loader.getClassLoader();
311324

312325
try {
313326
return org.springframework.util.ClassUtils.forName(repositoryInterface, classLoader);

0 commit comments

Comments
 (0)