diff --git a/src/main/java/org/springframework/data/elasticsearch/core/AbstractDefaultIndexOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/AbstractDefaultIndexOperations.java index 2ab488f4c..4b6ff001b 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/AbstractDefaultIndexOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/AbstractDefaultIndexOperations.java @@ -26,7 +26,6 @@ import org.elasticsearch.cluster.metadata.AliasMetadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.elasticsearch.UncategorizedElasticsearchException; import org.springframework.data.elasticsearch.annotations.Mapping; @@ -44,7 +43,7 @@ import org.springframework.util.StringUtils; /** * Base implementation of {@link IndexOperations} common to Transport and Rest based Implementations of IndexOperations. - * + * * @author Peter-Josef Meisch * @author Sascha Woo * @since 4.0 @@ -107,13 +106,10 @@ abstract class AbstractDefaultIndexOperations implements IndexOperations { Document settings = null; - if (AnnotatedElementUtils.hasAnnotation(clazz, Setting.class)) { - AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Setting.class); + Setting setting = AnnotatedElementUtils.findMergedAnnotation(clazz, Setting.class); - if (attributes != null) { - String settingPath = attributes.getString("settingPath"); - settings = loadSettings(settingPath); - } + if (setting != null) { + settings = loadSettings(setting.settingPath()); } if (settings == null) { @@ -230,21 +226,18 @@ abstract class AbstractDefaultIndexOperations implements IndexOperations { protected Document buildMapping(Class clazz) { // load mapping specified in Mapping annotation if present - if (AnnotatedElementUtils.hasAnnotation(clazz, Mapping.class)) { - AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Mapping.class); + Mapping mappingAnnotation = AnnotatedElementUtils.findMergedAnnotation(clazz, Mapping.class); + if (mappingAnnotation != null) { + String mappingPath = mappingAnnotation.mappingPath(); - if (attributes != null) { - String mappingPath = attributes.getString("mappingPath"); + if (StringUtils.hasText(mappingPath)) { + String mappings = ResourceUtil.readFileFromClasspath(mappingPath); - if (StringUtils.hasText(mappingPath)) { - String mappings = ResourceUtil.readFileFromClasspath(mappingPath); - - if (StringUtils.hasText(mappings)) { - return Document.parse(mappings); - } - } else { - LOGGER.info("mappingPath in @Mapping has to be defined. Building mappings using @Field"); + if (StringUtils.hasText(mappings)) { + return Document.parse(mappings); } + } else { + LOGGER.info("mappingPath in @Mapping has to be defined. Building mappings using @Field"); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/DefaultReactiveIndexOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/DefaultReactiveIndexOperations.java index 3a06ff8fc..abf83455a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/DefaultReactiveIndexOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/DefaultReactiveIndexOperations.java @@ -159,14 +159,11 @@ class DefaultReactiveIndexOperations implements ReactiveIndexOperations { @Override public Mono createMapping(Class clazz) { - if (AnnotatedElementUtils.hasAnnotation(clazz, Mapping.class)) { - AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Mapping.class); + Mapping mappingAnnotation = AnnotatedElementUtils.findMergedAnnotation(clazz, Mapping.class); - if (attributes != null) { - String mappingPath = clazz.getAnnotation(Mapping.class).mappingPath(); - return loadDocument(mappingPath, "@Mapping"); - } - } + if (mappingAnnotation != null) { + return loadDocument(mappingAnnotation.mappingPath(), "@Mapping"); + } String mapping = new MappingBuilder(converter).buildPropertyMapping(clazz); return Mono.just(Document.parse(mapping)); @@ -204,14 +201,11 @@ class DefaultReactiveIndexOperations implements ReactiveIndexOperations { @Override public Mono createSettings(Class clazz) { - if (AnnotatedElementUtils.hasAnnotation(clazz, Setting.class)) { - AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Setting.class); + Setting setting = AnnotatedElementUtils.findMergedAnnotation(clazz, Setting.class); - if (attributes != null) { - String settingPath = attributes.getString("settingPath"); - return loadDocument(settingPath, "@Setting"); - } - } + if (setting != null) { + return loadDocument(setting.settingPath(), "@Setting"); + } return Mono.just(getRequiredPersistentEntity(clazz).getDefaultSettings()); }