|
26 | 26 | import java.util.Set; |
27 | 27 |
|
28 | 28 | import org.springframework.beans.BeansException; |
29 | | -import org.springframework.beans.factory.config.BeanDefinition; |
30 | 29 | import org.springframework.context.ApplicationContext; |
31 | 30 | import org.springframework.context.ApplicationContextAware; |
32 | 31 | import org.springframework.context.annotation.Bean; |
33 | | -import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; |
34 | 32 | import org.springframework.context.annotation.Configuration; |
35 | 33 | import org.springframework.core.convert.converter.Converter; |
36 | | -import org.springframework.core.type.filter.AnnotationTypeFilter; |
37 | 34 | import org.springframework.data.convert.CustomConversions; |
38 | 35 | import org.springframework.data.convert.CustomConversions.StoreConversions; |
39 | 36 | import org.springframework.data.r2dbc.convert.MappingR2dbcConverter; |
|
49 | 46 | import org.springframework.data.relational.core.conversion.BasicRelationalConverter; |
50 | 47 | import org.springframework.data.relational.core.mapping.NamingStrategy; |
51 | 48 | import org.springframework.data.relational.core.mapping.Table; |
| 49 | +import org.springframework.data.util.TypeScanner; |
52 | 50 | import org.springframework.lang.Nullable; |
53 | 51 | import org.springframework.r2dbc.core.DatabaseClient; |
54 | 52 | import org.springframework.util.Assert; |
55 | | -import org.springframework.util.ClassUtils; |
56 | 53 | import org.springframework.util.StringUtils; |
57 | 54 |
|
58 | 55 | /** |
@@ -230,8 +227,9 @@ public MappingR2dbcConverter r2dbcConverter(R2dbcMappingContext mappingContext, |
230 | 227 | /** |
231 | 228 | * Register custom {@link Converter}s in a {@link CustomConversions} object if required. These |
232 | 229 | * {@link CustomConversions} will be registered with the {@link BasicRelationalConverter} and |
233 | | - * {@link #r2dbcMappingContext(Optional, R2dbcCustomConversions, RelationalManagedTypes)}. Returns an empty {@link R2dbcCustomConversions} |
234 | | - * instance by default. Override {@link #getCustomConverters()} to supply custom converters. |
| 230 | + * {@link #r2dbcMappingContext(Optional, R2dbcCustomConversions, RelationalManagedTypes)}. Returns an empty |
| 231 | + * {@link R2dbcCustomConversions} instance by default. Override {@link #getCustomConverters()} to supply custom |
| 232 | + * converters. |
235 | 233 | * |
236 | 234 | * @return must not be {@literal null}. |
237 | 235 | * @see #getCustomConverters() |
@@ -306,31 +304,18 @@ protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException { |
306 | 304 | * Scans the given base package for entities, i.e. R2DBC-specific types annotated with {@link Table}. |
307 | 305 | * |
308 | 306 | * @param basePackage must not be {@literal null}. |
309 | | - * @return |
310 | | - * @throws ClassNotFoundException |
| 307 | + * @return a set of classes identified as entities. |
311 | 308 | * @since 3.0 |
312 | 309 | */ |
313 | | - protected Set<Class<?>> scanForEntities(String basePackage) throws ClassNotFoundException { |
| 310 | + protected Set<Class<?>> scanForEntities(String basePackage) { |
314 | 311 |
|
315 | 312 | if (!StringUtils.hasText(basePackage)) { |
316 | 313 | return Collections.emptySet(); |
317 | 314 | } |
318 | 315 |
|
319 | | - Set<Class<?>> initialEntitySet = new HashSet<>(); |
320 | | - |
321 | | - if (StringUtils.hasText(basePackage)) { |
322 | | - |
323 | | - ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider( |
324 | | - false); |
325 | | - componentProvider.addIncludeFilter(new AnnotationTypeFilter(Table.class)); |
326 | | - |
327 | | - for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) { |
328 | | - |
329 | | - initialEntitySet |
330 | | - .add(ClassUtils.forName(candidate.getBeanClassName(), AbstractR2dbcConfiguration.class.getClassLoader())); |
331 | | - } |
332 | | - } |
333 | | - |
334 | | - return initialEntitySet; |
| 316 | + return TypeScanner.typeScanner(AbstractR2dbcConfiguration.class.getClassLoader()) // |
| 317 | + .forTypesAnnotatedWith(Table.class) // |
| 318 | + .scanPackages(basePackage) // |
| 319 | + .collectAsSet(); |
335 | 320 | } |
336 | 321 | } |
0 commit comments