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的性能
文章来自: http://www.chinaemail.com.cn/server/xtfl/Exchange/201109/66466.html SharePoint是微软历史上销售量增长最快的产品 ...
- C#多线程Thread
在项目中经常用到线程Thread,先做个简单记录,后面再完善下,方便以后参考.本人技术有限,如有不同见解之处,欢迎博友批评指正. 执行的线程Thread分无参数的,一个参数,多个参数的.直接看代码吧. ...
- JSON:使用json_encode函数解析结果为Null
1.首先,数据库中的json数据是这样的 2.仓鼠使用json_encode()函数进行解析json数据时,显示了一个NULL: 3.这时候,我们需要使用,表示在解析json之前,该json是有语法错 ...
- 非常全面的PHP header函数设置HTTP头的示例
突然看到这个,觉得很好,就拿过来了,如下: //定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header('Conten ...
- 【CCPC-Wannafly Winter Camp Day3 (Div1) G】排列(水题)
点此看题面 大致题意:已知 \(p\)为\(n\)的一个排列,定义\(A(p)_i=min_{j=1}^ip_j\),若用\(q_i\)表示\(p\)第\(i\)小的前缀的长度(以值为第一关键字,下标 ...
- vue中的js动画与Velocity.js结合
vue里面除了用css写动画,还可以用js写动画,vue的transition中,定义了几个动画钩子 第一个动画钩子:@before-enter <div id='app'> <tr ...
- win10自带应用图标显示感叹号无法打开如何解决(详细版)
现象 今天打开电脑图片时发现系统自带的大多应用都无法运行,这些应用图标上都显示着一个感叹号, 应用图标上的颜色被覆上了一层黑色点击后无法运行,自带的应用商店也无法打开,想重装软件都不行这是怎么回事呢? ...
- Java 字符串转码工具类
StringConvertUtils.java package javax.utils; /** * 字符串转码工具类 * * @author Logan * @createDate 2019-04- ...
- 缓冲区溢出实战教程系列(三):利用OllyDbg了解程序运行机制
想要进行缓冲区溢出的分析与利用,当然就要懂得程序运行的机制.今天我们就用动态分析神器ollydbg来了解一下在windows下程序是如何运行的. 戳这里看之前发布的文章: 缓冲区溢出实战教程系列(一) ...
- C++声明之CV限定符
目录 1.const 1.1 const obj 如果调用 non-const member fun会编译出错 经典错误 1.2 例子:STD里的操作符重载 1.3 例子:<cpp primer ...