zoukankan      html  css  js  c++  java
  • spring-@Component/@ComponentScan注解

    被@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
  • 相关阅读:
    小球掉落
    String当中与转换相关常用的方法有
    字符串的截取方法
    golang 管道
    golang--协程之间通信的方式
    golang--goroutine
    go 时间操作
    吉格勒定理
    检视阅读
    git branch -a发现分支显示不全
  • 原文地址:https://www.cnblogs.com/yintingting/p/6574615.html
Copyright © 2011-2022 走看看