Skip to content

Commit 1984fbd

Browse files
committed
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.
1 parent f72b446 commit 1984fbd

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616
package org.springframework.data.repository.config;
1717

18+
import lombok.extern.slf4j.Slf4j;
19+
1820
import java.util.ArrayList;
1921
import java.util.List;
22+
import java.util.stream.Collectors;
2023

2124
import javax.annotation.Nullable;
2225

23-
import org.slf4j.Logger;
24-
import org.slf4j.LoggerFactory;
2526
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
2627
import org.springframework.beans.factory.support.AbstractBeanDefinition;
2728
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -43,10 +44,9 @@
4344
* @author Oliver Gierke
4445
* @author Jens Schauder
4546
*/
47+
@Slf4j
4648
public class RepositoryConfigurationDelegate {
4749

48-
private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryConfigurationDelegate.class);
49-
5050
private static final String REPOSITORY_REGISTRATION = "Spring Data {} - Registering repository: {} - Interface: {} - Factory: {}";
5151
private static final String MULTIPLE_MODULES = "Multiple Spring Data modules found, entering strict repository configuration mode!";
5252

@@ -117,6 +117,11 @@ public List<BeanComponentDefinition> registerRepositoriesIn(BeanDefinitionRegist
117117
environment);
118118
List<BeanComponentDefinition> definitions = new ArrayList<>();
119119

120+
if (LOG.isDebugEnabled()) {
121+
LOG.debug("Scanning for repositories in packages {}.",
122+
configurationSource.getBasePackages().stream().collect(Collectors.joining(", ")));
123+
}
124+
120125
for (RepositoryConfiguration<? extends RepositoryConfigurationSource> configuration : extension
121126
.getRepositoryConfigurations(configurationSource, resourceLoader, inMultiStoreMode)) {
122127

@@ -133,9 +138,9 @@ public List<BeanComponentDefinition> registerRepositoriesIn(BeanDefinitionRegist
133138
AbstractBeanDefinition beanDefinition = definitionBuilder.getBeanDefinition();
134139
String beanName = configurationSource.generateBeanName(beanDefinition);
135140

136-
if (LOGGER.isDebugEnabled()) {
137-
LOGGER.debug(REPOSITORY_REGISTRATION, extension.getModuleName(), beanName,
138-
configuration.getRepositoryInterface(), configuration.getRepositoryFactoryBeanClassName());
141+
if (LOG.isDebugEnabled()) {
142+
LOG.debug(REPOSITORY_REGISTRATION, extension.getModuleName(), beanName, configuration.getRepositoryInterface(),
143+
configuration.getRepositoryFactoryBeanClassName());
139144
}
140145

141146
beanDefinition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, configuration.getRepositoryInterface());
@@ -144,6 +149,10 @@ public List<BeanComponentDefinition> registerRepositoriesIn(BeanDefinitionRegist
144149
definitions.add(new BeanComponentDefinition(beanDefinition, beanName));
145150
}
146151

152+
if (LOG.isDebugEnabled()) {
153+
LOG.debug("Finished repository scanning.");
154+
}
155+
147156
return definitions;
148157
}
149158

@@ -160,7 +169,7 @@ private boolean multipleStoresDetected() {
160169
.loadFactoryNames(RepositoryFactorySupport.class, resourceLoader.getClassLoader()).size() > 1;
161170

162171
if (multipleModulesFound) {
163-
LOGGER.info(MULTIPLE_MODULES);
172+
LOG.info(MULTIPLE_MODULES);
164173
}
165174

166175
return multipleModulesFound;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import lombok.NonNull;
2121
import lombok.RequiredArgsConstructor;
2222
import lombok.Value;
23+
import lombok.extern.slf4j.Slf4j;
2324

2425
import java.lang.reflect.Constructor;
2526
import java.lang.reflect.Method;
@@ -78,6 +79,7 @@
7879
* @author Christoph Strobl
7980
* @author Jens Schauder
8081
*/
82+
@Slf4j
8183
public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, BeanFactoryAware {
8284

8385
private static final BiFunction<Method, Object[], Object[]> REACTIVE_ARGS_CONVERTER = (method, o) -> {
@@ -287,6 +289,10 @@ public <T> T getRepository(Class<T> repositoryInterface, Object customImplementa
287289
@SuppressWarnings({ "unchecked" })
288290
public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fragments) {
289291

292+
if (LOG.isDebugEnabled()) {
293+
LOG.debug("Initializing repository instance for {}…", repositoryInterface.getName());
294+
}
295+
290296
Assert.notNull(repositoryInterface, "Repository interface must not be null!");
291297
Assert.notNull(fragments, "RepositoryFragments must not be null!");
292298

@@ -320,7 +326,13 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
320326
composition = composition.append(RepositoryFragment.implemented(target));
321327
result.addAdvice(new ImplementationMethodExecutionInterceptor(composition));
322328

323-
return (T) result.getProxy(classLoader);
329+
T repository = (T) result.getProxy(classLoader);
330+
331+
if (LOG.isDebugEnabled()) {
332+
LOG.debug("Finished creation of repository instance for {}.", repositoryInterface.getName());
333+
}
334+
335+
return repository;
324336
}
325337

326338
/**

0 commit comments

Comments
 (0)