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
  • 相关阅读:
    jmeter循环发送http请求
    判断字符串是否为日期格式
    正则表达式的部分替换 $1~$99
    js验证上传文件大小
    mongodb主从备份 和 手动主从切换
    openproject安装与使用
    软件项目开发常见错误
    使用selenium的WebDriver和ChromeDriver实现UI自动化
    shell ssh远程执行命令
    Flask入门
  • 原文地址:https://www.cnblogs.com/yintingting/p/6574615.html
Copyright © 2011-2022 走看看