一. <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. [C#.net]WinForm载入窗体完成后自动执行事件

    一.以下是网络上可搜索到的次序 当 Windows Form 应用程序启动时,会以下列顺序引发主要表单的启动事件:        System.Windows.Forms.Control.Handle ...

  2. mysql数据库的安装和基本使用

    一.数据库安装配置 1)数据库的概念 .数据库相关概念 数据库服务器(本质就是一个台计算机,该计算机之上安装有数据库管理软件的服务端) 数据库管理管理系统RDBMS(本质就是一个C/S架构的套接字软件 ...

  3. layer.alert没有垂直居中

    经查找是因为 <!DOCTYPE html> 这句没有写在整个页面的最顶部,将其放在整个页面的第一行就可以了. ps:原理不是很清楚

  4. https网站引用http路径的js和css失效解决办法

    Jazzy  html  2015-03-26 在https的网站中引用http路径的js或css会导致不起作用,其形如: Html <script src="http://code. ...

  5. VSCode 设置侧边栏字体大小;Visual Studio Code改变侧边栏大小

    1.代码改写,进入默认安装的如下路径 C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code\resources\app\out ...

  6. java并发控制工具类和集合等

    转载自:https://my.oschina.net/hosee/blog/607677 摘要: 本系列基于炼数成金课程,为了更好的学习,做了系列的记录. 本文主要介绍: 1.各种同步控制工具的使用 ...

  7. thinkphp3.2.3 数据库增删改查

    版本3.23 1. 多表查找一条数据 M('a表')->join("b表 on b表.id=a表.id")->where('条件')->find(); 2.查找一 ...

  8. AngularJS实战之ng-repeat的详细用法

    一.基本语法 {{$index}}:获取元素的下标. {{$first}}:判断当前元素是否是第一个元素,是则为true,否则:false: {{$last}}:判断当前元素是否是最后一个元素,是则为 ...

  9. 【慕课网实战】Spark Streaming实时流处理项目实战笔记一之铭文升级版

    第一章:课程介绍 铭文一级: VMware Fusion Mac上搭建:为了给大家演示如何使用我们的OOTB环境 Hadoop环境:虚拟机,我是远程登录 Mac 那么就不需要使用我们的OOTB环境 V ...

  10. 强制DataNode向NameNode上报blocks

    正常情况下,什么时候上报blocks,是由NameNode通过回复心跳响应的方式触发的. 一次机房搬迁中,原机房hadoop版本为2.7.2,新机房版本为2.8.0,采用先扩容再缩容的方式搬迁.由于新 ...