|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2013 the original author or authors. |
|
|
|
|
* Copyright 2013-2014 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -15,17 +15,24 @@
@@ -15,17 +15,24 @@
|
|
|
|
|
*/ |
|
|
|
|
package org.springframework.data.mongodb.config; |
|
|
|
|
|
|
|
|
|
import static org.springframework.beans.factory.config.BeanDefinition.*; |
|
|
|
|
import static org.springframework.data.mongodb.config.BeanNames.*; |
|
|
|
|
|
|
|
|
|
import java.lang.annotation.Annotation; |
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.config.BeanDefinition; |
|
|
|
|
import org.springframework.beans.factory.support.AbstractBeanDefinition; |
|
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
|
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
|
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition; |
|
|
|
|
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; |
|
|
|
|
import org.springframework.core.type.AnnotationMetadata; |
|
|
|
|
import org.springframework.data.auditing.IsNewAwareAuditingHandler; |
|
|
|
|
import org.springframework.data.auditing.config.AnnotationAuditingConfiguration; |
|
|
|
|
import org.springframework.data.auditing.config.AuditingBeanDefinitionRegistrarSupport; |
|
|
|
|
import org.springframework.data.config.ParsingUtils; |
|
|
|
|
import org.springframework.data.mapping.context.MappingContextIsNewStrategyFactory; |
|
|
|
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext; |
|
|
|
|
import org.springframework.data.mongodb.core.mapping.event.AuditingEventListener; |
|
|
|
|
import org.springframework.data.support.IsNewStrategyFactory; |
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
@ -57,7 +64,7 @@ class MongoAuditingRegistrar extends AuditingBeanDefinitionRegistrarSupport {
@@ -57,7 +64,7 @@ class MongoAuditingRegistrar extends AuditingBeanDefinitionRegistrarSupport {
|
|
|
|
|
Assert.notNull(annotationMetadata, "AnnotationMetadata must not be null!"); |
|
|
|
|
Assert.notNull(registry, "BeanDefinitionRegistry must not be null!"); |
|
|
|
|
|
|
|
|
|
registerIsNewStrategyFactoryIfNecessary(registry); |
|
|
|
|
defaultDependenciesIfNecessary(registry, annotationMetadata); |
|
|
|
|
super.registerBeanDefinitions(annotationMetadata, registry); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -92,14 +99,33 @@ class MongoAuditingRegistrar extends AuditingBeanDefinitionRegistrarSupport {
@@ -92,14 +99,33 @@ class MongoAuditingRegistrar extends AuditingBeanDefinitionRegistrarSupport {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param registry, the {@link BeanDefinitionRegistry} to use to register an {@link IsNewStrategyFactory} to. |
|
|
|
|
* Register default bean definitions for a {@link MongoMappingContext} and an {@link IsNewStrategyFactory} in case we |
|
|
|
|
* don't find beans with the assumed names in the registry. |
|
|
|
|
* |
|
|
|
|
* @param registry the {@link BeanDefinitionRegistry} to use to register the components into. |
|
|
|
|
* @param source the source which the registered components shall be registered with |
|
|
|
|
*/ |
|
|
|
|
private void registerIsNewStrategyFactoryIfNecessary(BeanDefinitionRegistry registry) { |
|
|
|
|
private void defaultDependenciesIfNecessary(BeanDefinitionRegistry registry, Object source) { |
|
|
|
|
|
|
|
|
|
if (!registry.containsBeanDefinition(MAPPING_CONTEXT)) { |
|
|
|
|
|
|
|
|
|
RootBeanDefinition definition = new RootBeanDefinition(MongoMappingContext.class); |
|
|
|
|
definition.setRole(ROLE_INFRASTRUCTURE); |
|
|
|
|
definition.setSource(source); |
|
|
|
|
|
|
|
|
|
registry.registerBeanDefinition(MAPPING_CONTEXT, definition); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!registry.containsBeanDefinition(IS_NEW_STRATEGY_FACTORY)) { |
|
|
|
|
|
|
|
|
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder |
|
|
|
|
.rootBeanDefinition(MappingContextIsNewStrategyFactory.class); |
|
|
|
|
builder.addConstructorArgReference(MAPPING_CONTEXT); |
|
|
|
|
|
|
|
|
|
AbstractBeanDefinition definition = ParsingUtils.getSourceBeanDefinition(builder, source); |
|
|
|
|
definition.setRole(ROLE_INFRASTRUCTURE); |
|
|
|
|
|
|
|
|
|
if (!registry.containsBeanDefinition(BeanNames.IS_NEW_STRATEGY_FACTORY)) { |
|
|
|
|
registry.registerBeanDefinition(BeanNames.IS_NEW_STRATEGY_FACTORY, |
|
|
|
|
BeanDefinitionBuilder.rootBeanDefinition(MappingContextIsNewStrategyFactory.class) |
|
|
|
|
.addConstructorArgReference(BeanNames.MAPPING_CONTEXT).getBeanDefinition()); |
|
|
|
|
registry.registerBeanDefinition(IS_NEW_STRATEGY_FACTORY, definition); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|