关于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. 2018.12.22 spoj7258 Lexicographical Substring Search(后缀自动机)

    传送门 samsamsam基础题. 题意简述:给出一个串,询问第kkk大的本质不同的串. 然而这就是弦论的简化版. 我们把samsamsam建出来然后贪心选择就行了. 代码: #include< ...

  2. 2018.12.15 spoj1812 Longest Common Substring(后缀自动机)

    传送门 后缀自动机模板题. 题意简述:求两个字串的最长公共子串长度. 对其中一个构建后缀自动机,用另外一个在上面跑即可. 代码: #include<bits/stdc++.h> #defi ...

  3. IDEA将项目导出war包方法(详细)

    右上角点击进入配置页面(如图)选择Artifcts 点击绿色的那个+号,选择Web Application:Archive; 设置名称,选择输出路径 下面开始打war包在Build下面选择Build ...

  4. shell常用符号的意义

    转自:http://blog.sina.com.cn/mo0928 感谢原作者!!! 跟網路農夫了解UNIX SHELL-(Bash scripting 简介 第四章 特殊符号) (2007-08-1 ...

  5. 工作总结(二):Web Design

    PHP框架:CakePHP 前端框架:Bootstrap Payment Data Transfer:https://developer.paypal.com/docs/classic/paypal- ...

  6. Application-identifier entitlement does not match问题的解决

    以下是一个老外的回答: This happened to me after installing a build from TestFlight and overwriting it with the ...

  7. QOpenGLFunctions的相关的使用(1)

    QOpenGLFunctions的使用 1.  QOpenGLFunctions  说明  QOpenGLFunctions 类提供了跨平台的OpenGl ES2.0 API版本. OpenGL 2. ...

  8. bootstrap table 前端搜索

    1.bootstrap-table对于前端的搜索可以通过官网设置,但发现前端搜索出现bug,网上找到一个bootstrap-table的扩充js  bootstrap-table-mytoolbar. ...

  9. RxSwift学习笔记2:Observable/生命周期/Event/oneNext/onError/onCompleted/

     Observable 是 Rx 的根基 官网:http://reactivex.io/ github地址:https://github.com/ReactiveX/RxSwift Observabl ...

  10. 1.html基础

    认识html 1.1 Hyper   text  markup   language 超文本标记语言. 超文本:超链接.(实现页面跳转) Html结构标准 < ! doctype html> ...