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
  • 相关阅读:
    常用颜色
    在VS2010中打开VS2012的项目
    vs2012 断点不能调试
    Setup Factory 打包.netframework 2.0
    Access 中数据库操作时提示from子句语法错误
    vs2012 .netFramwork2.0发布到xp
    c# access插入null值
    Visual Studio安装卸载模板
    Codeforces 455D
    ACdream 1157 (cdq分治)
  • 原文地址:https://www.cnblogs.com/yintingting/p/6574615.html
Copyright © 2011-2022 走看看