import注解的作用
时间: 2023-11-05 15:04:44 浏览: 80
@Import注解的作用是将实例快速导入到Spring的容器中。它可以以更加灵活便捷的方式将Bean注入到Spring容器中。@Import注解有三种用法。首先,@Import注解只能作用在类上。其次,可以使用ImportSelector接口来选择并返回应该根据导入的@Configuration类的AnnotationMetadata导入的类名。最后,可以直接在@Import注解中指定要导入的类。例如,在一个ImportConfig的@Configuration类中,可以使用@Import({TestA.class,TestB.class,SelfImportSelector.class})来导入TestA、TestB类以及通过SelfImportSelector选择的其他类。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [@Import注解使用](https://blog.csdn.net/m0_55806905/article/details/127967036)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [@Import注解的作用](https://blog.csdn.net/qq_34501351/article/details/109529113)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文