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
  • 相关阅读:
    js(5)关于this的指代值
    bootstrap(2)关于表单
    bootstrap(1)关于排版
    bootstrap基础(0)写在前面的一些话
    js(4) 继承
    js(3)面向对象的程序设计
    js(2)关于作用域和作用域链
    鼠标事件(jQuery方法)
    鼠标事件(JS原生方法)
    键盘事件(在输入框中输入内容后按回车键)
  • 原文地址:https://www.cnblogs.com/yintingting/p/6574615.html
Copyright © 2011-2022 走看看