关于component-scan操作(去除,失效)

这个spring中的配置项,可以扫描我们对应的包下面的类,自动把带上@component,@service,@controller, @repository的类加入spring容器中托管

注意哦,component-scan 会默认吧annotation-config打开

但是不仅仅是这些,我们还可以对其中的范围进行限制

我们可以通过include-fileter和exclude-filter进行包含和排除

注意我们的范围选定方式有5种!

在我们没有排除之前:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <context:component-scan base-package="cn.cutter">
<!-- 控制扫描范围 ,根据注解扫描进入容器-->
<context:include-filter type="annotation" expression="cn.cutter"/>
<!-- <context:exclude-filter type="aspectj" expression="* cn.cutter.noscan.*"/> -->
</context:component-scan>
<!-- <context:annotation-config /> 这个属性在component中默认已经是true了 --> <!-- 国际化配置 -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames">
<list>
<value>i18/users</value>
<value>i18/errormsg</value>
</list>
</property> </bean> <bean id="ttmRateService" class="cn.cutter.simplefx.service.impl.MockTTMRateServiceImpl"></bean> <bean id="fooBar" class="cn.cutter.start.resourceloader.FooBar" /> <bean id="fooBar2" class="cn.cutter.start.resourceloader.FooBar2" /> <bean id="resourceDemo" class="cn.cutter.start.resourceloader.ResourceDemo">
<property name="resource">
<value>classpath:applicationContext-bean.xml</value>
</property>
</bean> <!-- <bean id="myObject" class="cn.cutter.start.bean.MyObject"></bean> --> <!-- <alias name="FXNewsProvider" alias="provideralias"/> --> <!-- <bean id="test4key2" ></bean> <bean id="" class="..." lazy-init="true">
<constructor-arg>
<ref bean="" parent=""/>
</constructor-arg> <property name="test1">
<value>ttttt1</value>
<idref bean="ttttt1"/>
</property> <property name="test2">
<list>
<value>test2value</value>
<ref bean="test2222"/>
<idref bean="test22222"/>
<bean class="..."></bean>
</list>
</property> <property name="test3">
<set>
<value>test2value</value>
<ref bean="test2222"/>
<idref bean="test22222"/>
<bean class="..."></bean>
</set>
</property> <property name="test4">
<map>
<entry key="test4key1">
<value>something</value>
</entry> <entry key-ref="test5key2">
<list>
<value>test2value</value>
<ref bean="test2222"/>
<idref bean="test22222"/>
<bean class="..."></bean>
</list>
</entry>
</map>
</property> </bean> --> </beans>

测试

@Test
public void testScan() {
ApplicationContext ctx = this.before(); //TestScan
TestScan testScan = (TestScan) ctx.getBean("testScan");
if(testScan == null) {
System.out.println("扫描排除");
} else {
System.out.println("扫描进入");
testScan.sayHello();
}
}

结果展示:

【sping揭秘】10、SpringIOC容器扩展的更多相关文章

  1. 高并发秒杀系统--junit测试类与SpringIoc容器的整合

    1.原理是在Junit启动时加载SpringIoC容器 2.SpringIoC容器要根据Spring的配置文件加载 [示例代码] package org.azcode.dao; import org. ...

  2. 【转】Spring学习---SpringIOC容器的初始化过程

    [原文]https://www.toutiao.com/i6594400249429623304/ SpringIOC容器的初始化过程 简单来说,IoC容器的初始化是由refresh()方法来启动的, ...

  3. SpringIOC容器创建过程

    在测试时,经常使用这种方式来创建spring容器 //创建基于注解的springIOC容器 ApplicationContext applicationContext = new Annotation ...

  4. 100行代码撸完SpringIOC容器

    用过Spring框架的人一定都知道Spring的依赖注入控制反转;通俗的讲就是负责实例化对象 和 管理对象间的依赖 实现解耦. 我们来对比两段代码: UserController{ UserServi ...

  5. 深入理解Spring--动手实现一个简单的SpringIOC容器

    接触Spring快半年了,前段时间刚用Spring4+S2H4做完了自己的毕设,但是很明显感觉对Spring尤其是IOC容器的实现原理理解的不到位,说白了,就是仅仅停留在会用的阶段,有一颗想读源码的心 ...

  6. 容器扩展属性 IExtenderProvider 实现WinForm通用数据验证组件

    大家对如下的Tip组件使用应该不陌生,要想让窗体上的控件使用ToolTip功能,只需要拖动一个ToolTip组件到窗口,所有的控件就可以使用该功能,做信息提示. 本博文要记录的,就是通过容器扩展属性 ...

  7. 深入理解SpringIOC容器

    转载来源:[https://www.cnblogs.com/fingerboy/p/5425813.html] 前言: 在逛博客园的时候突然发现一篇关于事务的好文章,说起spring事物就离不开AOP ...

  8. SpringIOC容器装配Bean

    Spring 的core Container(Spring的核心容器)有四大部分:bean.context.core.expression 在进行Bean的配置时候,需要添加四个jar包 如下: 分别 ...

  9. Spring - SpringIOC容器详解

    一.什么是Spring IOC: Ioc—Inversion of Control,即“控制反转”,不是什么技术,而是一种设计思想. 在Java开发中,Ioc意味着将你设计好的对象交给容器控制,而不是 ...

随机推荐

  1. B+树和LSM比较(转)

    出处:https://blog.csdn.net/u013928917/article/details/75912045 B+树和LSM比较 在关系型数据库mysql中普遍使用B+树作为索引,在实际中 ...

  2. c语言struct和c++struct的区别

    1.定义 c语言中struct是用户自定义数据类型(UDT),是一些变量的集合体:c++中struct是抽象数据类型(ADT),能给用户提供接口,能定义成员函数,能继承,能实现多态 2.成员权限设置 ...

  3. C语言的问题,头文件:keil也许有漏洞

    2018-06-15   16:52:03 ------------------------------------------------------------------------------ ...

  4. HDU 5468 Puzzled Elena (dfs + 莫比乌斯反演)

    题意:给定一棵带权树,求每个点与其子树结点的权值互质的个数. 析:首先先要进行 dfs 遍历,len[i] 表示能够整除 i 的个数,在遍历的前和遍历后的差值就是子树的len值,有了这个值,就可以使用 ...

  5. WEB上传大文件解决方案

    众所皆知,web上传大文件,一直是一个痛.上传文件大小限制,页面响应时间超时.这些都是web开发所必须直面的. 本文给出的解决方案是:前端实现数据流分片长传,后面接收完毕后合并文件的思路.下面贴出简易 ...

  6. Django-类视图与中间件

    ------类视图 1.类视图引入 def register(request): """处理注册"""   # 获取请求方法,判断是GET/ ...

  7. Build Laravel Blog PigJian by PHP7 and Nginx on Ubuntu

    Recently, I found an interesting framework Laravel written by PHP. i have never used PHP to write an ...

  8. C#-vs2012学习笔记-惊奇于vs的强大和便利

    网站常用功能自动完成,包括网页和数据库.

  9. 2018/6/29 关于hashmap的总结

    hashMap和ConcurrentHashMap的区别 hashMap内部具体如何实现的 如果hashMap的key是一个自定义的类,怎么办 为什么重写equals还要重写hashcode 一.什么 ...

  10. CSS 基础 例子 背景色 & 背景图片

    背景简写形式 : body {background:#ffffff url('img_tree.png') no-repeat right top;} 一.背景色  background-color ...