My project has one hundred thousand beans+ to initialize into spring. However every time it needs several imnutes to complete its work. I found ClassPathBeanDefinitionScanner.doScan 's code which does work one by one.
So I have a question, because it use Set
My spring version : 5.1.19. Below is that current release code:
My Suggestion is that:
`protected Set
ConcurrentHashMap<BeanDefinition,Object> candidates = new ConcurrentHashMap<BeanDefinition, Object>();
Arrays.stream(basePackages).parallel().map(x->{
return findCandidateComponents(basePackage);
}).forEach(x->{
candidates.put(x,new Object());
});
for (String basePackage : basePackages) {
for (BeanDefinition candidate : candidates) {
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate);
candidate.setScope(scopeMetadata.getScopeName());
String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry);
if (candidate instanceof AbstractBeanDefinition) {
postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName);
}
if (candidate instanceof AnnotatedBeanDefinition) {
AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);
}
if (checkCandidate(beanName, candidate)) {
BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName);
definitionHolder =
AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
beanDefinitions.add(definitionHolder);
registerBeanDefinition(definitionHolder, this.registry);
}
}
}
return beanDefinitions;
}`
Comment From: snicoll
Thanks for the suggestion but post-processing bean definitions asynchronously is not possible at the moment. See also #13410