From a88748d79809ac969567cbeb840437ec44e81fe2 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 11 Mar 2021 15:07:56 +0100 Subject: [PATCH] Remove `@Persistent` from entity-scan include filters. We now only scan for entities annotated with `@Document` to avoid inclusion of non-MongoDB entities. Previously, types annotated (or meta-annotated) with `@Persistent` were included as MongoDB entity which could lead to mapping rule violations. Closes #3592 --- .../data/mongodb/config/MongoConfigurationSupport.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoConfigurationSupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoConfigurationSupport.java index 7dd481d57a..52ec72d171 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoConfigurationSupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoConfigurationSupport.java @@ -26,7 +26,6 @@ import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.core.convert.converter.Converter; import org.springframework.core.type.filter.AnnotationTypeFilter; -import org.springframework.data.annotation.Persistent; import org.springframework.data.convert.CustomConversions; import org.springframework.data.mapping.model.CamelCaseAbbreviatingFieldNamingStrategy; import org.springframework.data.mapping.model.FieldNamingStrategy; @@ -140,8 +139,7 @@ protected Set> getInitialEntitySet() throws ClassNotFoundException { } /** - * Scans the given base package for entities, i.e. MongoDB specific types annotated with {@link Document} and - * {@link Persistent}. + * Scans the given base package for entities, i.e. MongoDB specific types annotated with {@link Document}. * * @param basePackage must not be {@literal null}. * @return @@ -161,7 +159,6 @@ protected Set> scanForEntities(String basePackage) throws ClassNotFound ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider( false); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class)); - componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class)); for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {