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 ...
随机推荐
- 使用delphi-cross-socket 开发kbmmw smart http service
前几天我说了使用delphi-cross-socket 扩展kbmmw 的跨平台支持,今天我说一下使用 kbmMWCrossScoketHttpServerTransport 在linux 下支持 k ...
- ubuntu的应用中心打不开、闪退
原因没有细究,但问题已经解决简单粗暴: 1.更新列表 apt-get update apt-get dist-upgrade 2.重新安装应用中心 apt-get install --reinsta ...
- Idea项目如何迁移到Eclipse
CTRL + SHIFT + ALT + S键 (即File>Project Structure), 按照如图一样设置,设置完成后就可以直接导入到eclipse了
- 2019.01.08 bzoj4543: [POI2014]Hotel加强版(长链剖分+dp)
传送门 代码: 长链剖分好题. 题意:给你一棵树,问树上选三个互不相同的节点,使得这个三个点两两之间距离相等的方案数. 思路: 先考虑dpdpdp. fi,jf_{i,j}fi,j表示iii子树中离 ...
- 2018.06.26 NOIP模拟 纪念碑(线段树+扫描线)
题解: 题目背景 SOURCE:NOIP2015−GDZSJNZXSOURCE:NOIP2015-GDZSJNZXSOURCE:NOIP2015−GDZSJNZX(难) 题目描述 2034203420 ...
- tp5框架成功、失败提示模板修改
<!DOCTYPE html> <html> <head> <title> 页面自动中...跳转 等待时间:<?php echo($wait); ...
- ant Design和ant Design mobile的使用,并实现按需加载
1.全局安装yarn npm install -g create-react-app yarn 2.创建react项目,并用yarn start 运行 3.引入antd/引入antd-mobile y ...
- Win7 VS2013环境使用cuda_7.5.18
首先得吐槽下VS2015出来快一年了CUDA居然还不支持,没办法重装系统刚从2013升到2015,还得再装回一个2013用,只为学习CUDA... 然后安装的时候,如果你选择自定义组件安装,注意不要改 ...
- PHP函数gmstrftime()将秒数转换成天时分秒
http://yangjunwei.com/a/930.html PHP函数gmstrftime()将秒数转换成天时分秒 一个应用场景需要用到倒计时的时分秒,比如新浪微博授权有效期剩余: 7天16 ...
- 20169207《Linux内核原理与分析》第七周作业
这周作业基本分为两个方面,第一方面,阅读学习教材「Linux内核设计与实现 (Linux Kernel Development)」第教材第9,10章.第二方面.学习MOOC「Linux内核分析」第五讲 ...