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 ...
随机推荐
- 计算器的改良(NOIP2000)
题目链接:计算器的改良 这道题,不是很难,但代码也短不到哪去. 我们这里决定采取边读入边计算的方法,因为题目没有明确说式子有多长. 我们需要计算什么? 我们需要知道等号两边未知数的系数和常数项即可. ...
- python console 设立快捷键 学习源码 用到英语
arbitrary---随意 iterable----迭代 invalid syntax -----无效的语法 subscriptable ----可索引访问的
- 68.iOS设备尺寸及型号代码(iPhoneXR/XS)
所有设备型号官网地址: https://www.theiphonewiki.com/wiki/Models iPhone: 机型 像素 比例 像素密度 屏幕尺寸 机型代码 发布日期 iPhone 2g ...
- socketserver模块实现并发和连接合法性验证
一.socketserver模块 1.sockeserver的源码流程 2.简单的使用 socketserver服务端 import socketserver class MyServer(socke ...
- 2019.01.20 NOIP模拟 迅雷(kruskal/二分+并查集)
传送门 题意简述:给一张带权无向图,有a,ba,ba,b两类特殊点和普通点,问使得至少有一个aaa和一个bbb连通所需要的所有边边权最小值的最大值是多少. 思路: 一眼发现可以二分,考虑怎么check ...
- openstack网络基本概念(转)
OpenStack的Neutron能够管理OpenStack环境中的虚拟 网络基础设施(VNI).和物理网络基础设施(PNI). OpenStack的Neutron同意租户创建虚拟网络拓扑结构.包括的 ...
- MacOS使用常用配置
如何增加tree命令? 安装Homebrew步骤:http://blog.csdn.net/xianyiqi/article/details/51297562 安装npm步骤:https://blog ...
- Java应用分类
Java应用分类 一.应用程序.指在操作系统上直接运行的,不是浏览器,Java环境用本机的,需要在客户端安装,Java环境可以一起安装. 1.GUI图形界面应用程序 ...
- (转)WCF中神秘的“8733"端口和“Design_Time_Addresses”
转自:http://blog.csdn.net/bitfan/article/details/4193319 如果使用Visual Studio 2008 SP1开发WCF应用程序时,会发现当使用Vi ...
- 阿里云服务器 OSS的使用限制
使用限制 更新时间:2019-02-12 16:50:27 编辑 · OSS的使用限制及性能指标如下: 限制项 说明 归档存储 已经存储的数据从冷冻状态恢复到可读取状态需要 1 分钟的等待时间. ...