diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java index 7384000b6..9688ac496 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java @@ -15,13 +15,14 @@ */ package org.springframework.data.repository.config; +import lombok.extern.slf4j.Slf4j; + import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; @@ -43,10 +44,9 @@ import org.springframework.util.Assert; * @author Oliver Gierke * @author Jens Schauder */ +@Slf4j public class RepositoryConfigurationDelegate { - private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryConfigurationDelegate.class); - private static final String REPOSITORY_REGISTRATION = "Spring Data {} - Registering repository: {} - Interface: {} - Factory: {}"; private static final String MULTIPLE_MODULES = "Multiple Spring Data modules found, entering strict repository configuration mode!"; @@ -117,6 +117,11 @@ public class RepositoryConfigurationDelegate { environment); List definitions = new ArrayList<>(); + if (LOG.isDebugEnabled()) { + LOG.debug("Scanning for repositories in packages {}.", + configurationSource.getBasePackages().stream().collect(Collectors.joining(", "))); + } + for (RepositoryConfiguration configuration : extension .getRepositoryConfigurations(configurationSource, resourceLoader, inMultiStoreMode)) { @@ -133,9 +138,9 @@ public class RepositoryConfigurationDelegate { AbstractBeanDefinition beanDefinition = definitionBuilder.getBeanDefinition(); String beanName = configurationSource.generateBeanName(beanDefinition); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(REPOSITORY_REGISTRATION, extension.getModuleName(), beanName, - configuration.getRepositoryInterface(), configuration.getRepositoryFactoryBeanClassName()); + if (LOG.isDebugEnabled()) { + LOG.debug(REPOSITORY_REGISTRATION, extension.getModuleName(), beanName, configuration.getRepositoryInterface(), + configuration.getRepositoryFactoryBeanClassName()); } beanDefinition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, configuration.getRepositoryInterface()); @@ -144,6 +149,10 @@ public class RepositoryConfigurationDelegate { definitions.add(new BeanComponentDefinition(beanDefinition, beanName)); } + if (LOG.isDebugEnabled()) { + LOG.debug("Finished repository scanning."); + } + return definitions; } @@ -160,7 +169,7 @@ public class RepositoryConfigurationDelegate { .loadFactoryNames(RepositoryFactorySupport.class, resourceLoader.getClassLoader()).size() > 1; if (multipleModulesFound) { - LOGGER.info(MULTIPLE_MODULES); + LOG.info(MULTIPLE_MODULES); } return multipleModulesFound; diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java index b1dda83e0..1d8b20c1b 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java @@ -20,6 +20,7 @@ import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.Value; +import lombok.extern.slf4j.Slf4j; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -78,6 +79,7 @@ import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType; * @author Christoph Strobl * @author Jens Schauder */ +@Slf4j public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, BeanFactoryAware { private static final BiFunction REACTIVE_ARGS_CONVERTER = (method, o) -> { @@ -287,6 +289,10 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, @SuppressWarnings({ "unchecked" }) public T getRepository(Class repositoryInterface, RepositoryFragments fragments) { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing repository instance for {}…", repositoryInterface.getName()); + } + Assert.notNull(repositoryInterface, "Repository interface must not be null!"); Assert.notNull(fragments, "RepositoryFragments must not be null!"); @@ -320,7 +326,13 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, composition = composition.append(RepositoryFragment.implemented(target)); result.addAdvice(new ImplementationMethodExecutionInterceptor(composition)); - return (T) result.getProxy(classLoader); + T repository = (T) result.getProxy(classLoader); + + if (LOG.isDebugEnabled()) { + LOG.debug("Finished creation of repository instance for {}.", repositoryInterface.getName()); + } + + return repository; } /**