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.
This commit is contained in:
committed by
Mark Paluch
parent
b18e340b82
commit
2cf0e6520f
@@ -15,13 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.repository.config;
|
package org.springframework.data.repository.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
@@ -43,10 +44,9 @@ import org.springframework.util.Assert;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Jens Schauder
|
* @author Jens Schauder
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class RepositoryConfigurationDelegate {
|
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 REPOSITORY_REGISTRATION = "Spring Data {} - Registering repository: {} - Interface: {} - Factory: {}";
|
||||||
private static final String MULTIPLE_MODULES = "Multiple Spring Data modules found, entering strict repository configuration mode!";
|
private static final String MULTIPLE_MODULES = "Multiple Spring Data modules found, entering strict repository configuration mode!";
|
||||||
|
|
||||||
@@ -117,6 +117,11 @@ public class RepositoryConfigurationDelegate {
|
|||||||
environment);
|
environment);
|
||||||
List<BeanComponentDefinition> definitions = new ArrayList<>();
|
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
|
for (RepositoryConfiguration<? extends RepositoryConfigurationSource> configuration : extension
|
||||||
.getRepositoryConfigurations(configurationSource, resourceLoader, inMultiStoreMode)) {
|
.getRepositoryConfigurations(configurationSource, resourceLoader, inMultiStoreMode)) {
|
||||||
|
|
||||||
@@ -133,9 +138,9 @@ public class RepositoryConfigurationDelegate {
|
|||||||
AbstractBeanDefinition beanDefinition = definitionBuilder.getBeanDefinition();
|
AbstractBeanDefinition beanDefinition = definitionBuilder.getBeanDefinition();
|
||||||
String beanName = configurationSource.generateBeanName(beanDefinition);
|
String beanName = configurationSource.generateBeanName(beanDefinition);
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOGGER.debug(REPOSITORY_REGISTRATION, extension.getModuleName(), beanName,
|
LOG.debug(REPOSITORY_REGISTRATION, extension.getModuleName(), beanName, configuration.getRepositoryInterface(),
|
||||||
configuration.getRepositoryInterface(), configuration.getRepositoryFactoryBeanClassName());
|
configuration.getRepositoryFactoryBeanClassName());
|
||||||
}
|
}
|
||||||
|
|
||||||
beanDefinition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, configuration.getRepositoryInterface());
|
beanDefinition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, configuration.getRepositoryInterface());
|
||||||
@@ -144,6 +149,10 @@ public class RepositoryConfigurationDelegate {
|
|||||||
definitions.add(new BeanComponentDefinition(beanDefinition, beanName));
|
definitions.add(new BeanComponentDefinition(beanDefinition, beanName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug("Finished repository scanning.");
|
||||||
|
}
|
||||||
|
|
||||||
return definitions;
|
return definitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +169,7 @@ public class RepositoryConfigurationDelegate {
|
|||||||
.loadFactoryNames(RepositoryFactorySupport.class, resourceLoader.getClassLoader()).size() > 1;
|
.loadFactoryNames(RepositoryFactorySupport.class, resourceLoader.getClassLoader()).size() > 1;
|
||||||
|
|
||||||
if (multipleModulesFound) {
|
if (multipleModulesFound) {
|
||||||
LOGGER.info(MULTIPLE_MODULES);
|
LOG.info(MULTIPLE_MODULES);
|
||||||
}
|
}
|
||||||
|
|
||||||
return multipleModulesFound;
|
return multipleModulesFound;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import lombok.Getter;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -78,6 +79,7 @@ import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Jens Schauder
|
* @author Jens Schauder
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, BeanFactoryAware {
|
public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, BeanFactoryAware {
|
||||||
|
|
||||||
private static final BiFunction<Method, Object[], Object[]> REACTIVE_ARGS_CONVERTER = (method, o) -> {
|
private static final BiFunction<Method, Object[], Object[]> REACTIVE_ARGS_CONVERTER = (method, o) -> {
|
||||||
@@ -286,6 +288,10 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
|
|||||||
@SuppressWarnings({ "unchecked" })
|
@SuppressWarnings({ "unchecked" })
|
||||||
public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fragments) {
|
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(repositoryInterface, "Repository interface must not be null!");
|
||||||
Assert.notNull(fragments, "RepositoryFragments must not be null!");
|
Assert.notNull(fragments, "RepositoryFragments must not be null!");
|
||||||
|
|
||||||
@@ -319,7 +325,13 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
|
|||||||
composition = composition.append(RepositoryFragment.implemented(target));
|
composition = composition.append(RepositoryFragment.implemented(target));
|
||||||
result.addAdvice(new ImplementationMethodExecutionInterceptor(composition));
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user