22
22
import java .util .List ;
23
23
import java .util .Map ;
24
24
import java .util .Optional ;
25
+ import java .util .function .Consumer ;
25
26
import java .util .stream .Collectors ;
26
27
27
28
import org .aopalliance .intercept .MethodInterceptor ;
35
36
import org .springframework .beans .factory .BeanClassLoaderAware ;
36
37
import org .springframework .beans .factory .BeanFactory ;
37
38
import org .springframework .beans .factory .BeanFactoryAware ;
39
+ import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
40
+ import org .springframework .context .ApplicationContext ;
38
41
import org .springframework .core .convert .support .DefaultConversionService ;
39
42
import org .springframework .core .convert .support .GenericConversionService ;
40
43
import org .springframework .core .log .LogMessage ;
44
+ import org .springframework .core .metrics .ApplicationStartup ;
45
+ import org .springframework .core .metrics .StartupStep ;
41
46
import org .springframework .data .projection .DefaultMethodInvokingMethodInterceptor ;
42
47
import org .springframework .data .projection .ProjectionFactory ;
43
48
import org .springframework .data .projection .SpelAwareProxyProjectionFactory ;
@@ -269,12 +274,21 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
269
274
logger .debug (LogMessage .format ("Initializing repository instance for %s…" , repositoryInterface .getName ()));
270
275
}
271
276
277
+ ApplicationStartup applicationStartup = getStartup ();
278
+
272
279
Assert .notNull (repositoryInterface , "Repository interface must not be null!" );
273
280
Assert .notNull (fragments , "RepositoryFragments must not be null!" );
274
281
282
+ StartupStep repositoryInit = applicationStartup .start ("spring.data.repository.init" );
283
+
284
+ StartupStep repositoryMetadataStep = applicationStartup .start ("spring.data.repository.metadata" );
275
285
RepositoryMetadata metadata = getRepositoryMetadata (repositoryInterface );
286
+ repositoryMetadataStep .end ();
287
+
288
+ StartupStep repositoryCompositionStep = applicationStartup .start ("spring.data.repository.metadata" );
276
289
RepositoryComposition composition = getRepositoryComposition (metadata , fragments );
277
290
RepositoryInformation information = getRepositoryInformation (metadata , composition );
291
+ repositoryCompositionStep .end ();
278
292
279
293
validate (information , composition );
280
294
@@ -291,7 +305,9 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
291
305
292
306
result .addAdvisor (ExposeInvocationInterceptor .ADVISOR );
293
307
308
+ StartupStep repositoryPostprocessorsStep = applicationStartup .start ("spring.data.repository.postprocessors" );
294
309
postProcessors .forEach (processor -> processor .postProcess (result , information ));
310
+ repositoryPostprocessorsStep .end ();
295
311
296
312
if (DefaultMethodInvokingMethodInterceptor .hasDefaultMethods (repositoryInterface )) {
297
313
result .addAdvice (new DefaultMethodInvokingMethodInterceptor ());
@@ -313,9 +329,21 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
313
329
.debug (LogMessage .format ("Finished creation of repository instance for {}." , repositoryInterface .getName ()));
314
330
}
315
331
332
+ repositoryInit .end ();
316
333
return repository ;
317
334
}
318
335
336
+ ApplicationStartup getStartup () {
337
+
338
+ try {
339
+ ApplicationStartup applicationStartup = beanFactory != null ? beanFactory .getBean (ApplicationStartup .class ) : ApplicationStartup .DEFAULT ;
340
+ return applicationStartup != null ? applicationStartup : ApplicationStartup .DEFAULT ;
341
+ }
342
+ catch (NoSuchBeanDefinitionException e ) {
343
+ return ApplicationStartup .DEFAULT ;
344
+ }
345
+ }
346
+
319
347
/**
320
348
* Returns the {@link ProjectionFactory} to be used with the repository instances created.
321
349
*
0 commit comments