25
25
26
26
import org .apache .commons .logging .Log ;
27
27
import org .apache .commons .logging .LogFactory ;
28
-
28
+ import org . springframework . beans . factory . config . ConfigurableBeanFactory ;
29
29
import org .springframework .beans .factory .config .DependencyDescriptor ;
30
30
import org .springframework .beans .factory .parsing .BeanComponentDefinition ;
31
31
import org .springframework .beans .factory .support .AbstractBeanDefinition ;
34
34
import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
35
35
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
36
36
import org .springframework .context .annotation .ContextAnnotationAutowireCandidateResolver ;
37
+ import org .springframework .context .support .GenericApplicationContext ;
37
38
import org .springframework .core .env .Environment ;
38
39
import org .springframework .core .env .EnvironmentCapable ;
39
40
import org .springframework .core .env .StandardEnvironment ;
40
41
import org .springframework .core .io .ResourceLoader ;
41
42
import org .springframework .core .io .support .SpringFactoriesLoader ;
42
43
import org .springframework .core .log .LogMessage ;
44
+ import org .springframework .core .metrics .ApplicationStartup ;
45
+ import org .springframework .core .metrics .StartupStep ;
43
46
import org .springframework .data .repository .core .support .RepositoryFactorySupport ;
44
47
import org .springframework .lang .Nullable ;
45
48
import org .springframework .util .Assert ;
@@ -143,6 +146,11 @@ public List<BeanComponentDefinition> registerRepositoriesIn(BeanDefinitionRegist
143
146
configurationSource .getBasePackages ().stream ().collect (Collectors .joining (", " ))));
144
147
}
145
148
149
+ ApplicationStartup startup = getStartup (registry );
150
+ StartupStep repoScan = startup .start ("spring.data.repository.scanning" );
151
+ repoScan .tag ("data-module" , extension .getModuleName ());
152
+ repoScan .tag ("packages" , configurationSource .getBasePackages ().stream ().collect (Collectors .joining (", " )));
153
+
146
154
watch .start ();
147
155
148
156
Collection <RepositoryConfiguration <RepositoryConfigurationSource >> configurations = extension
@@ -184,6 +192,9 @@ public List<BeanComponentDefinition> registerRepositoriesIn(BeanDefinitionRegist
184
192
185
193
watch .stop ();
186
194
195
+ repoScan .tag ("repository.count" , Integer .toString (configurations .size ()));
196
+ repoScan .end ();
197
+
187
198
if (logger .isInfoEnabled ()) {
188
199
logger .info (LogMessage .format ("Finished Spring Data repository scanning in %s ms. Found %s %s repository interfaces." , //
189
200
watch .getLastTaskTimeMillis (), configurations .size (), extension .getModuleName ()));
@@ -208,7 +219,6 @@ private static void potentiallyLazifyRepositories(Map<String, RepositoryConfigur
208
219
}
209
220
210
221
DefaultListableBeanFactory beanFactory = DefaultListableBeanFactory .class .cast (registry );
211
-
212
222
AutowireCandidateResolver resolver = beanFactory .getAutowireCandidateResolver ();
213
223
214
224
if (!Arrays .asList (ContextAnnotationAutowireCandidateResolver .class , LazyRepositoryInjectionPointResolver .class )
@@ -253,6 +263,23 @@ private boolean multipleStoresDetected() {
253
263
return multipleModulesFound ;
254
264
}
255
265
266
+ ApplicationStartup getStartup (BeanDefinitionRegistry registry ) {
267
+
268
+ if (ConfigurableBeanFactory .class .isInstance (registry )) {
269
+ return ((ConfigurableBeanFactory )registry ).getApplicationStartup ();
270
+ }
271
+
272
+ if (DefaultListableBeanFactory .class .isInstance (registry )) {
273
+ return ((DefaultListableBeanFactory )registry ).getBeanProvider (ApplicationStartup .class ).getIfAvailable (() -> ApplicationStartup .DEFAULT );
274
+ }
275
+
276
+ if (GenericApplicationContext .class .isInstance (registry )) {
277
+ return ((GenericApplicationContext )registry ).getDefaultListableBeanFactory ().getApplicationStartup ();
278
+ }
279
+
280
+ return ApplicationStartup .DEFAULT ;
281
+ }
282
+
256
283
/**
257
284
* Customer {@link ContextAnnotationAutowireCandidateResolver} that also considers all injection points for lazy
258
285
* repositories lazy.
0 commit comments