一. <context:annotation-config/>

此标签支持一些注入属性的注解, 列如:@Autowired, @Resource注解

二. <context:component-scan/>

几个关键属性

1. use-default-filters: 默认为true, 支持@Controller, @Service, @Repository, @Component注解

2. annotation-config: 默认为true, 相当于开启<context:annotation-config/>标签

3. base-package: 指定扫描包的路径, 包括子包

两个子标签

1. <context:exclude-filter/>: 表示排除

2. <context:include-filter/>: 表示增加

常用配置

<!-- springmvc -->

<context:component-scan base-package="com.waston.controller" use-default-filters="false">
  <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<!-- spring -->

<context:component-scan base-package="com.waston">
  <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

表示springmvc只扫描com.waston.controller及其子包, 并且只扫描@Controller注解

spring扫描com.waston及其子包, 包括com.waston.controller, 但是不扫描@Controller注解

注:use-default-filters="false"必须要加, 否则默认为true, 也就是说会扫描上面说的四个注解,那么

<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>就不起作用了.

Spring 扫描标签<context:component-scan/>的更多相关文章

  1. Spring 配置 Annotation <context:annotation-config> 和 <context:component-scan>标签的诠释及区别

    Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别 <cont ...

  2. [Spring Boot] Use Component Scan to scan for Bean

    Component Scan is important concept when we want to create Bean. Currently we know what, for the cla ...

  3. Spring MVC 解读——<context:component-scan/>

    转自:http://my.oschina.net/HeliosFly/blog/203149 作者:GoodLoser. Spring MVC 解读---<context:component-s ...

  4. 这一次搞懂Spring自定义标签以及注解解析原理

    前言 在上一篇文章中分析了Spring是如何解析默认标签的,并封装为BeanDefinition注册到缓存中,这一篇就来看看对于像context这种自定义标签是如何解析的.同时我们常用的注解如:@Se ...

  5. spring注解注入:<context:component-scan>详解

    spring从2.5版本开始支持注解注入,注解注入可以省去很多的xml配置工作.由于注解是写入java代码中的,所以注解注入会失去一定的灵活性,我们要根据需要来选择是否启用注解注入. 我们首先看一个注 ...

  6. Spring component-scan 标签的实现

    在以前文章Spring自定义标签实现中,曾说过,在sprin g 配置文件中,除了be an beans import 常用的标签意外,其他的标签都是遵循Spring 自定义标签的扩展机制进行实现功能 ...

  7. spring中关于<context:component-scan>的使用说明(转)

    https://blog.csdn.net/liuxingsiye/article/details/52171508 通常情况下我们在创建spring项目的时候在xml配置文件中都会配置这个表情,配置 ...

  8. Spring使用标签注解来简化xml书写

    一.步骤 在配置文件中,引入context命名空间 <beans xmlns="http://www.springframework.org/schema/beans" xm ...

  9. Spring MVC标签<mvc: annotation-driven />小结 原

    转自:https://my.oschina.net/u/1156626/blog/881483 mvc:annotation-driven的作用 Spring 3.0.x中使用了mvc:annotat ...

随机推荐

  1. java中HashMap的基本方法使用

    遍历,添加词,等等 package test; import java.util.HashMap; import java.util.Iterator; import java.util.ArrayL ...

  2. NOIP水题测试(2017082301)

    你们从题目也能看出来今天的题是很水的. 前几期答案还没出,效率有点低,谅解,谅解. 今天的答案应该会出的很快. 下面给题目: 时间限制:3小时 题目一:旅行家的预算 题目二:进制转换 题目三:乘积最大 ...

  3. python学习 day1 (3月1日)

    01 cpu 内存 硬盘 操作系统 CPU:中央处理器,相当于人大脑. 飞机 内存:临时存储数据. 8g,16g, 高铁 1,成本高. 2,断电即消失. 硬盘:长期存储大量的数据. 1T 512G等等 ...

  4. Codeforces Round #524 (Div. 2) F. Katya and Segments Sets(主席树)

    https://codeforces.com/contest/1080/problem/F 题意 有k个区间,区间的种类有n种,有m个询问(n,m<=1e5,k<=3e5),每次询问a,b ...

  5. C[a,b]向量空间中的函数的线性相关性

  6. 删除一直处于deleting状态的数据卷

    一.场景 有一个volume数据卷hzb-1G-xxxxxx创建在nc8的ceph节点上,并且该数据卷的但是有一天nc8节点坏掉了.当我们删除hzb-1G-xxxxxx的时候,就会一直处于deleti ...

  7. s4-介质访问控制子层-1 MAC子层

    数据链路层被分成了两个子层:MAC和LLC MAC子层要解决什么问题? 介质访问控制(Madia Access Control) 数据通信方式 单播(unicast):One - to - One ...

  8. 第12章:MongoDB-CRUD操作--文档--查询--游标详解

    ①是什么游标 游标不是查询结果,可以理解为数据在遍历过程中的内部指针,其返回的是一个资源,或者说数据读取接口. 客户端通过对游标进行一些设置就能对查询结果进行有效地控制,如可以限制查询得到的结果数量. ...

  9. UVa 11021 Tribles (概率DP + 组合数学)

    题意:有 k 只小鸟,每只都只能活一天,但是每只都可以生出一些新的小鸟,生出 i 个小鸟的概率是 Pi,问你 m 天所有的小鸟都死亡的概率是多少. 析:先考虑只有一只小鸟,dp[i] 表示 i 天全部 ...

  10. 20155205 信息安全技术第二次实验 Windows口令破解

    20155205 信息安全技术第二次实验 Windows口令破解 实验原理 一.口令破解方法 口令破解主要有两种方法:字典破解和暴力破解. 字典破解是指通过破解者对管理员的了解,猜测其可能使用某些信息 ...