From be34b4e5033b03df191f99e4b71fde0fcdb03a29 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 23 Jan 2014 13:21:50 +0100 Subject: [PATCH] DATAMONGO-822 - Enable CDI repositories to be instantiated eagerly. From the CDI extension we now use the callback newly introduced in Spring Data Commons to enable it to trigger eager initialization. See also: DATACMNS-416. --- .../cdi/MongoRepositoryExtension.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryExtension.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryExtension.java index 37bbdab51..e6f5c802e 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryExtension.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. @@ -33,6 +33,7 @@ import javax.enterprise.inject.spi.ProcessBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.repository.cdi.CdiRepositoryBean; import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport; /** @@ -76,26 +77,29 @@ public class MongoRepositoryExtension extends CdiRepositoryExtensionSupport { Set qualifiers = entry.getValue(); // Create the bean representing the repository. - Bean repositoryBean = createRepositoryBean(repositoryType, qualifiers, beanManager); + CdiRepositoryBean repositoryBean = createRepositoryBean(repositoryType, qualifiers, beanManager); if (LOG.isInfoEnabled()) { LOG.info(String.format("Registering bean for %s with qualifiers %s.", repositoryType.getName(), qualifiers)); } // Register the bean to the container. + registerBean(repositoryBean); afterBeanDiscovery.addBean(repositoryBean); } } /** - * Creates a {@link Bean}. + * Creates a {@link CdiRepositoryBean} for the repository of the given type. * - * @param The type of the repository. - * @param repositoryType The class representing the repository. - * @param beanManager The BeanManager instance. - * @return The bean. + * @param the type of the repository. + * @param repositoryType the class representing the repository. + * @param qualifiers the qualifiers to be applied to the bean. + * @param beanManager the BeanManager instance. + * @return */ - private Bean createRepositoryBean(Class repositoryType, Set qualifiers, BeanManager beanManager) { + private CdiRepositoryBean createRepositoryBean(Class repositoryType, Set qualifiers, + BeanManager beanManager) { // Determine the MongoOperations bean which matches the qualifiers of the repository. Bean mongoOperations = this.mongoOperations.get(qualifiers);