/**
* perform a scan within the specified base packages.
* @param basepackages the packages to check for annotated classes
* @return number of beans registered
*/
public int scan(string... basepackages) {
int beancountatscanstart = this.registry.getbeandefinitioncount();
doscan(basepackages);
// register annotation config processors, if necessary.
if (this.includeannotationconfig) {
annotationconfigutils.registerannotationconfigprocessors(this.registry);
}
return (this.registry.getbeandefinitioncount() - beancountatscanstart);
}
/**
* perform a scan within the specified base packages,
* returning the registered bean definitions.
* <p>this method does <i>not</i> register an annotation config processor
* but rather leaves this up to the caller.
* @param basepackages the packages to check for annotated classes
* @return set of beans registered if any for tooling registration purposes (never {@code null})
*/
protected set<beandefinitionholder> doscan(string... basepackages) {
assert.notempty(basepackages, "at least one base package must be specified");
set<beandefinitionholder> beandefinitions = new linkedhashset<beandefinitionholder>();
for (string basepackage : basepackages) {
set<beandefinition> candidates = findcandidatecomponents(basepackage);
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;
}