@ComponentScan
将为您提供包(或/ )@Component
中带有注释的所有类的列表。为此,我想他们使用反射来枚举包中的所有类并找到带有该注释的类。@Service
@Repository
但是,根据StackOverflow 的其他答案,由于工作方式的原因,您无法可靠地枚举包中的所有类ClassLoader
。那么@ComponentScan
看似如何做到这一点呢?
@ComponentScan
将为您提供包(或/ )@Component
中带有注释的所有类的列表。为此,我想他们使用反射来枚举包中的所有类并找到带有该注释的类。@Service
@Repository
但是,根据StackOverflow 的其他答案,由于工作方式的原因,您无法可靠地枚举包中的所有类ClassLoader
。那么@ComponentScan
看似如何做到这一点呢?
@ComponentScan
工作方式不同。工作流程很快就放在这里:
Resource
对象中从 Spring 源代码中查看的类:
ComponentScanAnnotationParser
AnnotationConfigUtils
ClassPathBeanDefinitionScanner
BeanDefinitionReaderUtils
DefaultListableBeanFactory