实现对Bean1类的@ComponentScan注解的扫描
自定义实现一个BeanFactoryPostProcessor
//模拟实现ComponentScan
public class ComponentScanProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) configurableListableBeanFactory;
SimpleMetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
BeanNameGenerator nameGenerator = new AnnotationBeanNameGenerator();
//用AnnotationUtils查找此类上有没有ComponentScan注解
ComponentScan componentScan = AnnotationUtils.findAnnotation(Bean1.class, ComponentScan.class);
//不为空,有注解
if (componentScan != null) {
String[] packages = componentScan.basePackages();
for (String path : packages) {
//包名