Advertisement

SpringBoot 系列文章之 @Component 和 @ComponentScan 解析

阅读量:

通过@Bean注解逐个将Bean注入到Spring IoC容器中,操作过程较为繁琐。幸运的是,Spring框架提供了扫描装配Bean的机制,能够简化这一流程。在将Bean装配至IoC容器时,所依赖的注解为@Component以及@ComponentScan。其中,@Component用于标识哪些类需要被扫描并纳入Spring IoC容器管理,而@ComponentScan则用于指定扫描装配Bean的具体策略。默认情况下,@ComponentScan仅会对当前所在包及其子包进行扫描。以下是@ComponentScan的相关源码实现:

复制代码
  
    
   // IntelliJ API Decompiler stub source generated from a class file
    
   // Implementation of methods is not available
    
  
    
 package org.springframework.context.annotation;
    
  
    
 @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
    
 @java.lang.annotation.Target({java

全部评论 (0)

还没有任何评论哟~