一. <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. bootstrap 中 css 与 javascript 的使用

    1.css 1.1.选择器 1.2.子选择器: css 里的子元素用符号'>'表示.如下示例是表示拥有table样式的表盒,其thead元素内的tr元素如果有th的话,则应用该样式. .tabl ...

  2. delphi 10 seattle 安卓服务开发(一)

    从delphi 开始支持安卓的开发开始, 安卓service 开发一直都是delphier 绕不过去的坎, 以前也有开发service  的方法,但是都是手工处理启动文件,而且要修改很多东西,基本上成 ...

  3. docker 批量操作容器

    docker stop $(sudo docker ps -q)

  4. Oracle导入的常见语句

    登录sql > sqlplus / as sysdba 创建表空间sql > create tablespace TABLESPACE datafile 'e:\tables1.dbf' ...

  5. java 模拟登录新浪微博(通过cookie)

    这几天一直在研究新浪微博的爬虫,发现爬取微博的数据首先要登录.本来打算是通过账号和密码模拟浏览器登录.但是现在微博的登录机制比较复杂.通过账号密码还没有登录成功QAQ.所以就先记录下,通过cookie ...

  6. 2018.10.31 NOIP模拟 几串字符(数位dp+组合数学)

    传送门 如果观察到性质其实也不是很难想. 然而考试的时候慌得一批只有心思写暴力233. 下面是几个很有用的性质: c0,1+1≥c1,0≥c0,1c_{0,1 }+1 ≥ c_{1,0} ≥ c_{0 ...

  7. python知识积累

    1. 安装requirements.txt依赖: pip install -r requirements.txt 生成requirements.txt文件: pip freeze > requi ...

  8. 检索 COM 类工厂中 CLSID 为 {10021F00-E260-11CF-AE68-00AA004A34D5} 的组件失败,原因是出现以下错误: 80040154 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))。

    ASP.NET利用SQLDMO可以实现在线备份.还原数据库等各种功能. 由于客户的数据库和WEB服务不再同一台服务器,把网站部署在服务器上以后,运行程序,提示如下错误 当使用Interop.SQLDM ...

  9. Comment类型

    注释在DOM中是通过Comment类型来表示的. nodeType 8 nodeName #Comment nodeValue 注释的内容 parentNode 可能是Document或Element ...

  10. python_day1_python简单介绍

    一.python解释器的种类 我们都知道python是一种解释型的语言,那python在执行的过程中必须要通过解释器来执行,那python的解释器到底分为哪些呢? 1.Cpython CPython是 ...