@ComponentScan注释类型的参数含义,包含excludeFilters,includeFilters等其他参数

来源:互联网 发布:一元提现微信红包软件 编辑:程序博客网 时间:2024/06/11 16:44

在看《Spring in action》的时候,看到如下的一个类:

package spittr.config;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.ComponentScan.Filter;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.EnableWebMvc;import org.springframework.context.annotation.FilterType;@Configuration //配置Spring容器@ComponentScan(basePackages={"spitter"},excludeFilters={@Filter(type=FilterType.ANNOTATION,value=EnableWebMvc.class)})public class RootConfig {}
@ComponentScan是告诉Spring 哪个packages 的用注解标识的类 会被spring自动扫描并且装入bean容器。

基本的basePackages参数是用于扫描带注释组件的基本包。。那么excludeFilters呢?其他参数呢?反正百度前三页列表没有答案(没有黑百度的意思)。然后找文档,百度翻译了一下(百度翻译还挺好用的。)

basePackageClasses:对basepackages()指定扫描注释组件包类型安全的替代。

excludeFilters:指定不适合组件扫描的类型。

includeFilters:指定哪些类型有资格用于组件扫描。

lazyInit:指定是否应注册扫描的beans为lazy初始化。
nameGenerator:用于在Spring容器中的检测到的组件命名。
resourcePattern:控制可用于组件检测的类文件。
scopedProxy:指出代理是否应该对检测元件产生,在使用过程中会在代理风格时尚的范围是必要的。
scopeResolver:用于解决检测到的组件的范围。
useDefaultFilters:指示是否自动检测类的注释 @Component@Repository@Service, or @Controller 应启用。
valuebasePackages()别名
具体用法和代码段部分一样,至于里面的具体参数,那是另一段问题了。待更。。。。

0 0
原创粉丝点击