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 ...
随机推荐
- Mac 环境通用
mac 下更新 .bash_profile 文件 1.打开terminal(终端) 2.cd ~ ( 进入当前用户的home目录) 3.open .bash_profile (打开.bash_prof ...
- Java:斐波那契数列
斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10 ...
- 2018.10.25 bzoj4565: [Haoi2016]字符合并(区间dp+状压)
传送门 当看到那个k≤8k\le 8k≤8的时候就知道需要状压了. 状态定义:f[i][j][k]f[i][j][k]f[i][j][k]表示区间[i,j][i,j][i,j]处理完之后的状态为kkk ...
- windows下Oracle数据库完全删除
1.1 停止所有oracle的服务 1.2 删除安装路径 app及其下所有文件 1.3 删除注册表 regedit 进入 在下列列表中找到与oracle相关的注册表项删除 1.HKEY_L ...
- High-radix routers
The idea is to reduce H (hops), by adding explicit links between physically distant routers, thus re ...
- hadoop学习笔记-目录
以下是hadoop学习笔记的顺序: hadoop学习笔记(一):概念和组成 hadoop学习笔记(二):centos7三节点安装hadoop2.7.0 hadoop学习笔记(三):hdfs体系结构和读 ...
- exec函数
概念 当进程调用一种exec函数时,该进程执行的程序完全替换为新程序,新程序从main函数开始执行.调用exec并不创建新进程,所以前后的进程ID并未改变.exec只是用磁盘上的一个新程序替换了当前进 ...
- python模块:shutil
"""Utility functions for copying and archiving files and directory trees. XXX The fun ...
- PKG_CONFIG_PATH变量 与 ld.so.conf 文件
一.编译和连接 一般来说,如果库的头文件不在 /usr/include 目录中,那么在编译的时候需要用 -I 参数指定其路径.由于同一个库在不同系统上可能位于不同的目录下,用户安装库的时候也可以将库安 ...
- application.properties /application.yml官网查看配置;springboot application.properties 官网查看,info yml 查看;springboot.yml查看info;springboot.yml查看Actuator监控中心info
官网查看: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#appendix 查看info ...