|
59 | 59 | import org.springframework.lang.Nullable;
|
60 | 60 | import org.springframework.util.Assert;
|
61 | 61 | import org.springframework.util.ClassUtils;
|
| 62 | +import org.springframework.util.ObjectUtils; |
62 | 63 | import org.springframework.util.StringUtils;
|
63 | 64 | import org.springframework.util.xml.DomUtils;
|
64 | 65 | import org.w3c.dom.Element;
|
@@ -94,8 +95,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
|
94 | 95 | String id = element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
|
95 | 96 | id = StringUtils.hasText(id) ? id : DEFAULT_CONVERTER_BEAN_NAME;
|
96 | 97 |
|
97 |
| - String autoIndexCreation = element.getAttribute("auto-index-creation"); |
98 |
| - boolean autoIndexCreationEnabled = StringUtils.hasText(autoIndexCreation) && Boolean.parseBoolean(autoIndexCreation); |
| 98 | + boolean autoIndexCreationEnabled = isAutoIndexCreationEnabled(element); |
99 | 99 |
|
100 | 100 | parserContext.pushContainingComponent(new CompositeComponentDefinition("Mapping Mongo Converter", element));
|
101 | 101 |
|
@@ -196,11 +196,33 @@ private RuntimeBeanReference getValidator(Object source, ParserContext parserCon
|
196 | 196 | return new RuntimeBeanReference(validatorName);
|
197 | 197 | }
|
198 | 198 |
|
| 199 | + private static boolean isAutoIndexCreationEnabled(Element element) { |
| 200 | + |
| 201 | + String autoIndexCreation = element.getAttribute("auto-index-creation"); |
| 202 | + return StringUtils.hasText(autoIndexCreation) && Boolean.parseBoolean(autoIndexCreation); |
| 203 | + } |
| 204 | + |
| 205 | + /** |
| 206 | + * Create and register the {@link BeanDefinition} for a {@link MongoMappingContext} if not explicitly referenced by a |
| 207 | + * given {@literal mapping-context-ref} {@link Element#getAttribute(String) attribuite}. |
| 208 | + * |
| 209 | + * @return the mapping context bean name. |
| 210 | + * @deprecated since 4.3. Use |
| 211 | + * {@link #potentiallyCreateMappingContext(Element, ParserContext, BeanDefinition, String, boolean)} |
| 212 | + * instead. |
| 213 | + */ |
| 214 | + @Deprecated(since = "4.3", forRemoval = true) |
199 | 215 | public static String potentiallyCreateMappingContext(Element element, ParserContext parserContext,
|
200 | 216 | @Nullable BeanDefinition conversionsDefinition, @Nullable String converterId) {
|
201 | 217 | return potentiallyCreateMappingContext(element, parserContext, conversionsDefinition, converterId, false);
|
202 | 218 | }
|
203 | 219 |
|
| 220 | + /** |
| 221 | + * Create and register the {@link BeanDefinition} for a {@link MongoMappingContext} if not explicitly referenced by a |
| 222 | + * given {@literal mapping-context-ref} {@link Element#getAttribute(String) attribuite}. |
| 223 | + * |
| 224 | + * @return the mapping context bean name. |
| 225 | + */ |
204 | 226 | public static String potentiallyCreateMappingContext(Element element, ParserContext parserContext,
|
205 | 227 | @Nullable BeanDefinition conversionsDefinition, @Nullable String converterId, boolean autoIndexCreation) {
|
206 | 228 |
|
@@ -280,8 +302,10 @@ private BeanDefinition getCustomConversions(Element element, ParserContext parse
|
280 | 302 | ManagedList<BeanMetadataElement> converterBeans = new ManagedList<>();
|
281 | 303 | List<Element> converterElements = DomUtils.getChildElementsByTagName(customerConvertersElement, "converter");
|
282 | 304 |
|
283 |
| - for (Element listenerElement : converterElements) { |
284 |
| - converterBeans.add(parseConverter(listenerElement, parserContext)); |
| 305 | + if (!ObjectUtils.isEmpty(converterElements)) { |
| 306 | + for (Element listenerElement : converterElements) { |
| 307 | + converterBeans.add(parseConverter(listenerElement, parserContext)); |
| 308 | + } |
285 | 309 | }
|
286 | 310 |
|
287 | 311 | // Scan for Converter and GenericConverter beans in the given base-package
|
|
0 commit comments