Spring 扫描标签<context:component-scan/>
一. <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/>的更多相关文章
- Spring 配置 Annotation <context:annotation-config> 和 <context:component-scan>标签的诠释及区别
Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别 <cont ...
- [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 ...
- Spring MVC 解读——<context:component-scan/>
转自:http://my.oschina.net/HeliosFly/blog/203149 作者:GoodLoser. Spring MVC 解读---<context:component-s ...
- 这一次搞懂Spring自定义标签以及注解解析原理
前言 在上一篇文章中分析了Spring是如何解析默认标签的,并封装为BeanDefinition注册到缓存中,这一篇就来看看对于像context这种自定义标签是如何解析的.同时我们常用的注解如:@Se ...
- spring注解注入:<context:component-scan>详解
spring从2.5版本开始支持注解注入,注解注入可以省去很多的xml配置工作.由于注解是写入java代码中的,所以注解注入会失去一定的灵活性,我们要根据需要来选择是否启用注解注入. 我们首先看一个注 ...
- Spring component-scan 标签的实现
在以前文章Spring自定义标签实现中,曾说过,在sprin g 配置文件中,除了be an beans import 常用的标签意外,其他的标签都是遵循Spring 自定义标签的扩展机制进行实现功能 ...
- spring中关于<context:component-scan>的使用说明(转)
https://blog.csdn.net/liuxingsiye/article/details/52171508 通常情况下我们在创建spring项目的时候在xml配置文件中都会配置这个表情,配置 ...
- Spring使用标签注解来简化xml书写
一.步骤 在配置文件中,引入context命名空间 <beans xmlns="http://www.springframework.org/schema/beans" xm ...
- Spring MVC标签<mvc: annotation-driven />小结 原
转自:https://my.oschina.net/u/1156626/blog/881483 mvc:annotation-driven的作用 Spring 3.0.x中使用了mvc:annotat ...
随机推荐
- 用模糊查询like语句时如果要查是否包含%字符串该如何写
- 2018.12.22 bzoj3473: 字符串(后缀自动机+启发式合并)
传送门 调代码调的我怀疑人生. 启发式合并用迭代写怎么都跑不过(雾 换成了dfsdfsdfs版本的终于过了233. 题意简述:求给出nnn个字串,对于每个给定的字串求出其有多少个字串在至少kkk个剩下 ...
- 2018.12.08 codeforces 914D. Bash and a Tough Math Puzzle(线段树)
传送门 线段树辣鸡题. 题意简述:给出一个序列,支持修改其中一个数,以及在允许自行修改某个数的情况下询问区间[l,r][l,r][l,r]的gcdgcdgcd是否可能等于一个给定的数. 看完题就感觉是 ...
- poj-2406(字符串hash)
题目链接:传送门 思路:字符串hash,终止条件竟然判断错了,真是太大意了. #include<iostream> #include<cstdio> #include<c ...
- pyinstaller基本操作
pyinstaller 打包错误http://www.fmwei.com/linux/pyinstaller-lib-error.html 只需要复制python安装目录下的动态库到系统地动态库目录即 ...
- ubuntu上安装win7系统(64位的)
http://www.linuxidc.com/Linux/2012-11/74195.htm deb文件在ubuntu上直接用dpkg -i xxx.deb 如果虚拟机上只显示32位,则可能是cpu ...
- 怎么通过tomcat的catalina.out查看日志
进入tomcat的logs目录下:cd apache-tomcat/logs/ 查看logs下的文件和目录:ll 可以找到catalina.out文件: 实时查看日志: tail -fn 100 ...
- VIP之FrameBuffer
2.VIP Frame Buffer 1.原来我是一直存在一个疑惑,demo上说VIP Frame Buffer输出是固定的60fps,但是在NiosII的程序中我没有找到设置输出为60fps的设置 ...
- Codeforces Round#412 Div.2
A. Is it rated? 题面 Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codefo ...
- android Activity中设置setResult 没有触发onActivityResult
昨天修改<manifest 文件中activity 的 模式为单例模式:android:launchMode="singleTask" ,发现我的onActivityResu ...