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>配置, ...
随机推荐
- SharePoint 2010 VS.net 2010 断点调试
当IE打开之后 1在代码的项目:右键:重新生成 2用WSPBuilder的Copy to GAC 3IE要调试的页面:刷新 4用WSPBuilder的Attach to IIS Worker Proc ...
- AOP术语分析
初看这么多术语,一下子都不好接受,慢慢来,很快就会搞懂. 通知.增强处理(Advice) 就是你想要的功能,也就是上说的安全.事物.日子等.你给先定义好,然后再想用的地方用一下.包含Aspect的一段 ...
- jquery对radio的操作汇总
1.JQuery控制radio选中和不选中 通过name $("input:radio[name="analyfsftype"]").eq(0).attr(&q ...
- oracle自动异地备份数据库
需求:实现oracle自动异地备份数据库 分析:1.oracle备份数据库 2.自动备份(定时) 3.非本地备份(因为如果备份到本地的话,如果硬件设备损坏可能导致数据丢失) 知识点:1.备 ...
- PHP : 数据库中int类型保存时间并通过年月份时分秒进行显示
1.表设计: 2.数据库操作页面:将时间戳插入到数据库中 我们到数据库中可以看到: 3.我们将数据进行显示: 页面结果:(二维数组) 4.以为用mysqli_fetch_all得到的是二维数组,那么我 ...
- 6.Netbackup-Oracle数据库恢复演练报告(下)
1.1 Oracle数据库恢复 目录 1 安装新的客户端 2 新建异机恢复文件 3 新建数据库实例 4 建立spfile文件 5 建立数据文件夹 6 启动数据库到nomount状态 7 列出备份信息 ...
- c# 语法 字符串内插
结果截屏 参考文章 https://www.cnblogs.com/csproj/p/Interpolated_Strings.html c# 6.0语法 https://www.cnblogs.co ...
- Spring boot 集成Spring Security
依赖jar <dependency> <groupId>org.springframework.cloud</groupId> <artifactId> ...
- TryParse()的用法
DateTime dt = new DateTime(); DateTime.TryParse(txtName.text.trim(),out dt); string str1 = dt.ToStri ...
- ES6初识-Decorator
开始先按照个插件 npm install babel-plugin-transform-decorators-lagacy --save-dev 1.扩充和修改类的行为 2.修改的行为@readonl ...