From febc09a529c89b5e7b2fcbc0e774b67457d19dee Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 12 Oct 2023 17:39:33 -0700 Subject: [PATCH] Fix bug in GemFireComponentClassTypeScanner caused by component class resolution. We now supply the ClassLoader used to resolve GemFire/Geode entities to the Spring ClassPathScanningCandidateComponentProvider allowing entity classes to be resolved in all contexts (e.g. Spring Boot generated JARs). Additionally, SDG now provides configuration via a hidden property (spring.data.gemfire.classpath.scan.parallel) to tune the classpath scanning function (Stream). The default value for parallizing the Stream used during classpath scanning is now false. Closes #657 --- .../support/GemFireComponentClassTypeScanner.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/support/GemFireComponentClassTypeScanner.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/support/GemFireComponentClassTypeScanner.java index 3c9b9563..dff9b8dc 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/support/GemFireComponentClassTypeScanner.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/support/GemFireComponentClassTypeScanner.java @@ -33,6 +33,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.core.env.Environment; import org.springframework.core.env.StandardEnvironment; +import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.type.filter.TypeFilter; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -56,6 +57,9 @@ import org.slf4j.LoggerFactory; @SuppressWarnings("unused") public class GemFireComponentClassTypeScanner implements Iterable { + protected static final String GEMFIRE_COMPONENT_CLASSPATH_SCAN_PARALLEL_PROPERTY = + "spring.data.gemfire.classpath.scan.parallel"; + /** * Factory method to construct an instance of the {@link GemFireComponentClassTypeScanner} initialized with * the given array of base packages to scan. @@ -208,7 +212,10 @@ public class GemFireComponentClassTypeScanner implements Iterable { ClassPathScanningCandidateComponentProvider componentProvider = newClassPathScanningCandidateComponentProvider(); - stream(this.spliterator(), true) + boolean streamInParallel = getEnvironment() + .getProperty(GEMFIRE_COMPONENT_CLASSPATH_SCAN_PARALLEL_PROPERTY, Boolean.class, Boolean.FALSE); + + stream(this.spliterator(), streamInParallel) .flatMap(packageName -> componentProvider.findCandidateComponents(packageName).stream()) .forEach(beanDefinition -> Optional.ofNullable(beanDefinition.getBeanClassName()) @@ -258,6 +265,8 @@ public class GemFireComponentClassTypeScanner implements Iterable { this.excludes.forEach(componentProvider::addExcludeFilter); this.includes.forEach(componentProvider::addIncludeFilter); + componentProvider.setResourceLoader(new DefaultResourceLoader(getEntityClassLoader())); + return componentProvider; }