被@Component注解标注的注解有:@Service, @Repository, @Controller, @Configuration

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Indexed
public @interface Component { /**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component.
* @return the suggested component name, if any (or empty String otherwise)
*/
String value() default ""; }
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration { @AliasFor(annotation = Component.class)
String value() default ""; }
@ComponentScan会扫描带有@Component注解的类
处理类:
ConfigurationClassParser
扫描类:
ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateComponentProvider 
protected void registerDefaultFilters() {
this.includeFilters.add(new AnnotationTypeFilter(Component.class));

@ComponentScan:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Repeatable(ComponentScans.class) @since 1.8
public @interface ComponentScan {

一般的注解只能写一次,而被@Repeatable标注的注解可以写多次

@ComponentScan(basePackages = "com")
@ComponentScan(basePackages = "com.example")
public class Demo
05-26 10:50