码迷,mamicode.com
首页 > 其他好文 > 详细

context:component-scan

时间:2016-08-06 08:35:37      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

Scans the classpath for annotated components that will be auto-registered as Spring beans. By default, the Spring-provided @Component, @Repository, @Service, and @Controller stereotypes will be detected. Note: This tag implies the effects of the ‘annotation-config‘ tag, activating @Required, @Autowired, @PostConstruct, @PreDestroy, @Resource, @PersistenceContext and @PersistenceUnit annotations in the component classes, which is usually desired for autodetected components (without external configuration). Turn off the ‘annotation-config‘ attribute to deactivate this default behavior, for example in order to use custom BeanPostProcessor definitions for handling those annotations. Note: You may use placeholders in package paths, but only resolved against system properties (analogous to resource paths). A component scan results in new bean definition being registered; Spring‘s PropertyPlaceholderConfigurer will apply to those bean definitions just like to regular bean definitions, but it won‘t apply to the component scan settings themselves. See javadoc for org.springframework.context.annotation.ComponentScan for information on code-based alternatives to bootstrapping component-scanning.

  • @Component
  • @Repository
  • @Service
  • @Controller
<xsd:attribute name="base-package" type="xsd:string" use="required">...</xsd:attribute>
<xsd:attribute name="resource-pattern" type="xsd:string">...</xsd:attribute>
<xsd:attribute name="use-default-filters" type="xsd:boolean" default="true">...</xsd:attribute>
<xsd:attribute name="annotation-config" type="xsd:boolean" default="true">...</xsd:attribute>
<xsd:attribute name="name-generator" type="xsd:string">...</xsd:attribute>
<xsd:attribute name="scope-resolver" type="xsd:string">...</xsd:attribute>
<xsd:attribute name="scoped-proxy">...</xsd:attribute>

 

<xsd:element name="include-filter" type="filterType" minOccurs="0" maxOccurs="unbounded">...</xsd:element>
<xsd:element name="exclude-filter" type="filterType" minOccurs="0" maxOccurs="unbounded">...</xsd:element>

 

作用:

自动寻找被特定注解类标识的bean注册到 spring容器

@Component 是最基本的组件 ,和标签的名字一样 <context:component-scan

有一个属性是annotation-config 默认值是true ,默认是开启自动注入的。功能同<context:annotation-config /> 无需重复填写。

back-package 是 扫描的这个文件夹下的

use-default-filters 是扫描文件夹下的全部

filterType 有 5个值,点击看明细

技术分享

context:component-scan

标签:

原文地址:http://www.cnblogs.com/zno2/p/4691401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!