spring里面的context:component-scan
原文:http://jinnianshilongnian.iteye.com/blog/1762632
component-scan的作用的自动扫描,把扫描到加了注解Java文件都注册成bean
- <context:component-scan base-package="com.target">
- </context:component-scan>
今天在看一个代码项目时,看到有人使用了类似如下配置。看字面意思是要把@Service的注解包括进来,把@Controller的注解排除在外。
然后那个代码分别在Springmvc的配置文件里面把@Service和@Repository排除,在Spring配置文件中把@Controller排除。
至于为什么要排除,我起初以为性能问题,比如springmvc只需要关注controller,spring只需要关注service和repository。但是这是错误的认识,具体原因在最前面那个链接里有。
同时include-filter也可以把base-packge包之外的其他包的给包括进来。
include-filter如果放在exclude-filter后面则会报错。
- <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
同时,context:component-scan还有一个默认属性use-default-filters="true",默认是true,即扫描Component(包括service、controller和repository)
当只想包括某个注解时,需要显式关闭这个属性
- <context:component-scan base-package="com.target" use-default-filters="false">
- <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
- </context:component-scan>
spring里面的context:component-scan的更多相关文章
- spring里面的ioc的理解?
spring里面的ioc就是控制反转,其实现核心是DI(依赖注入),控制反转不向以前java代码里面,通过new关键字来实现创建对象,这样每段代码之间的耦合度就比较高,为了降低每个小模块之间的耦合度, ...
- jquery对象里面的context参数
jquery源码: jQuery = function( selector, context ) { // The jQuery object is actually just the init co ...
- spring 里面的StringUtils,先放这儿,有时间研究吧
/* * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Vers ...
- redis如何在spring里面的bean配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- [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源码分析-core.io包里面的类
前些日子看<深入理解javaweb开发>时,看到第一章java的io流,发觉自己对io流真的不是很熟悉.然后看了下JDK1.7中io包的一点点代码,又看了org.springframewo ...
- Spring MVC 解读——<context:component-scan/>
转自:http://my.oschina.net/HeliosFly/blog/203149 作者:GoodLoser. Spring MVC 解读---<context:component-s ...
- Spring 配置 Annotation <context:annotation-config> 和 <context:component-scan>标签的诠释及区别
Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别 <cont ...
- spring配置注解context:annotation-config和context:component-scan区别
Spring 中在使用注解(Annotation)会涉及到< context:annotation-config> 和 < context:component-scan>配置, ...
随机推荐
- [SVN]TortoiseSVN工具培训3─使用基本流程和图标说明
1.SVN的使用基本流程 注意:对于文件编辑方面,上图的编辑副本操作前建议进行Get lock操作,以防出现后续的冲突等异常报错. 2.SVN的基本图标说明
- django定时任务小插件
需求 每天请求一封邮件,并读取该邮件 这个其实可以使用linux 自带了crontab实现,但是毕竟是django 开发.想着不知道有没有方法可以从django 中实现. 简单搜索了下,这方面的方法确 ...
- ALPS语言学校(西雅图)|ALPS Language School (Seattle)
http://www.swliuxue.com/school-3879.html 所属国家: 美国 所在省洲: 华盛顿州 所在城市: 华盛顿州 建校时间: 1992年 学校类型: 院校 学校类别: 私 ...
- April 12 2017 Week 15 Wednesday
Genius often betrays itself into great errors. 天才常被天才误. Genius can help us get greater achievements, ...
- sublime text2卸载和重新安装(转载)
很多同学使用 sublime text2 的时候,出现一些奇怪的bug,且重启无法修复. 于是,就会想到卸载 sublime text2 再重新安装. 然而,你会发现,重新安装后,这个bug任然存在, ...
- 【转载】#402 - Value Equality vs. Reference Equality
When we normally think of "equality",we're thinking of value equality - the idea that the ...
- Last_IO_Errno: 1062
主键冲突的错误 1062 模拟错误: 在主库上操作: create table test100(id int not null,name varchar(20),primary key(id) ...
- bzoj4836 [Lydsy2017年4月月赛]二元运算
Description 定义二元运算 opt 满足 现在给定一个长为 n 的数列 a 和一个长为 m 的数列 b ,接下来有 q 次询问.每次询问给定一个数字 c 你需要求出有多少对 (i, j) ...
- IIS/IIS Express中遇到的证书问题
上面这幅图大家应该不陌生(觉得陌生的话就不用看下面的内容了,呵呵),再放上中英两段关键字: 根据验证过程,远程证书无效. The remote certificate is invalid accor ...
- .clone事件当你克隆的时候,DOM节点是克隆出来了,但是克隆出来的节点不能运行时事件 ...
解决办法如下在clone()里面加个参数true,即可完成事件的植入.即:.clone(true).clone( [ withDataAndEvents ], [ deepWithDataAndEve ...