Browse Source

DATACMNS-1367 - Improved debug logging to better identify scanning and initialization of repositories.

Added debug logging in RepositoryFactorySupport and RepositoryConfigurationDelegate so that the scanning and the instantiation of repositories can be a lot easier identified in the logs.
pull/354/head
Oliver Gierke 7 years ago
parent
commit
1984fbdb56
No known key found for this signature in database
GPG Key ID: 6E42B5787543F690
  1. 25
      src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java
  2. 14
      src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java

25
src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java

@ -15,13 +15,14 @@ @@ -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; @@ -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 { @@ -117,6 +117,11 @@ public class RepositoryConfigurationDelegate {
environment);
List<BeanComponentDefinition> definitions = new ArrayList<>();
if (LOG.isDebugEnabled()) {
LOG.debug("Scanning for repositories in packages {}.",
configurationSource.getBasePackages().stream().collect(Collectors.joining(", ")));
}
for (RepositoryConfiguration<? extends RepositoryConfigurationSource> configuration : extension
.getRepositoryConfigurations(configurationSource, resourceLoader, inMultiStoreMode)) {
@ -133,9 +138,9 @@ public class RepositoryConfigurationDelegate { @@ -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 { @@ -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 { @@ -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;

14
src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java

@ -20,6 +20,7 @@ import lombok.Getter; @@ -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; @@ -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<Method, Object[], Object[]> REACTIVE_ARGS_CONVERTER = (method, o) -> {
@ -287,6 +289,10 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, @@ -287,6 +289,10 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
@SuppressWarnings({ "unchecked" })
public <T> T getRepository(Class<T> 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, @@ -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;
}
/**

Loading…
Cancel
Save