组件注册——@ComponentScan自动扫描组件指定扫描规则
生活随笔
收集整理的這篇文章主要介紹了
组件注册——@ComponentScan自动扫描组件指定扫描规则
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
包掃描、只要標注了@Controller、@Service、@Repository,@Component
IOCTest.java
package com.atguigu.test;import org.junit.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import com.atguigu.config.MainConfig;public class IOCTest {@Testpublic void test01(){AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);String[] definitionNames = applicationContext.getBeanDefinitionNames();for (String name : definitionNames) {System.out.println(name);}} }@ComponentScan value:指定要掃描的包 excludeFilters = Filter[] :指定掃描的時候按照什么規(guī)則排除那些組件 includeFilters = Filter[] :指定掃描的時候只需要包含哪些組件 FilterType.ANNOTATION:按照注解 FilterType.ASSIGNABLE_TYPE:按照給定的類型; FilterType.ASPECTJ:使用ASPECTJ表達式 FilterType.REGEX:使用正則指定 FilterType.CUSTOM:使用自定義規(guī)則
總結(jié)
以上是生活随笔為你收集整理的组件注册——@ComponentScan自动扫描组件指定扫描规则的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高级指令——top指令【作用:查看服务器
- 下一篇: 快速入门JVM