【sping揭秘】10、SpringIOC容器扩展
关于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容器扩展的更多相关文章
- 高并发秒杀系统--junit测试类与SpringIoc容器的整合
1.原理是在Junit启动时加载SpringIoC容器 2.SpringIoC容器要根据Spring的配置文件加载 [示例代码] package org.azcode.dao; import org. ...
- 【转】Spring学习---SpringIOC容器的初始化过程
[原文]https://www.toutiao.com/i6594400249429623304/ SpringIOC容器的初始化过程 简单来说,IoC容器的初始化是由refresh()方法来启动的, ...
- SpringIOC容器创建过程
在测试时,经常使用这种方式来创建spring容器 //创建基于注解的springIOC容器 ApplicationContext applicationContext = new Annotation ...
- 100行代码撸完SpringIOC容器
用过Spring框架的人一定都知道Spring的依赖注入控制反转;通俗的讲就是负责实例化对象 和 管理对象间的依赖 实现解耦. 我们来对比两段代码: UserController{ UserServi ...
- 深入理解Spring--动手实现一个简单的SpringIOC容器
接触Spring快半年了,前段时间刚用Spring4+S2H4做完了自己的毕设,但是很明显感觉对Spring尤其是IOC容器的实现原理理解的不到位,说白了,就是仅仅停留在会用的阶段,有一颗想读源码的心 ...
- 容器扩展属性 IExtenderProvider 实现WinForm通用数据验证组件
大家对如下的Tip组件使用应该不陌生,要想让窗体上的控件使用ToolTip功能,只需要拖动一个ToolTip组件到窗口,所有的控件就可以使用该功能,做信息提示. 本博文要记录的,就是通过容器扩展属性 ...
- 深入理解SpringIOC容器
转载来源:[https://www.cnblogs.com/fingerboy/p/5425813.html] 前言: 在逛博客园的时候突然发现一篇关于事务的好文章,说起spring事物就离不开AOP ...
- SpringIOC容器装配Bean
Spring 的core Container(Spring的核心容器)有四大部分:bean.context.core.expression 在进行Bean的配置时候,需要添加四个jar包 如下: 分别 ...
- Spring - SpringIOC容器详解
一.什么是Spring IOC: Ioc—Inversion of Control,即“控制反转”,不是什么技术,而是一种设计思想. 在Java开发中,Ioc意味着将你设计好的对象交给容器控制,而不是 ...
随机推荐
- 将项目部署到 github上(部署到码云操作一样,前提是有码云账号)
来源:http://www.cnblogs.com/fengxiongZz/p/6477456.html 首先你需要自己的网页文件(俗称项目) 第一步:登录到Github上,新建一个repositor ...
- ELASTIC SEARCH 性能调优
ELASTICSEARCH 性能调优建议 创建索引调优 1.在创建索引的使用使用批量的方式导入到ES. 2.使用多线程的方式导入数据库. 3.增加默认刷新时间. 默认的刷新时间是1秒钟,这样会产生太多 ...
- CHAPITRE II
J'ai ainsi vécu seul, sans personne avec qui parler véritablement, jusqu'à une panne[pan][机]故障 dans ...
- Jquery 的ajax里边不能识别$(this)
确实不能用,在ajax外面弄个变量$this= $(this),然后在里面用就行了 在jQuery使用ajax后$(this)失效,原因很简单,$(this)指向的是最近调用它的jquery对象,即$ ...
- 交换机的Access口与Trunk口
基本概念 Access类型的端口只能属于1个VLAN,一般用于连接计算机的端口:Trunk类型的端口可以允许多个VLAN通过,可以接收和发送多个VLAN的报文,一般用于交换机之间连接的端口: 处理流程 ...
- vue中的路由独享守卫的理解
1.vue中路由独享守卫意思就是对这个路由有一个单独的守卫,因为他的守卫方式于其他的凡是不太同 独享守卫于前置守卫使用方法大致是一样的 在路由配置的时候进行配置, { path:'/login', c ...
- 【王者荣耀之IT大神版】铭文说明
铭文共分五级: 一级:仅有老师提供的笔记 二级:添加了自己的听课笔记 三级:添加问题+解决方案(常遇到的问题以及自己实践上遇到的问题,排位赛遇到的遗忘点) 四级:熟记铭文与并添加联想学过的知识 五级: ...
- python输出显示颜色
显示颜色格式:\033[显示方式;字体色;背景色m......[\033[0m] ------------------------------------------- --------------- ...
- 从npm到vue和nodejs
https://www.npmjs.com.cn/ vue和nodejs Windows 下安装NPM:https://www.cnblogs.com/interdrp/p/6779973.html ...
- bzoj2002(lct模板)
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #inclu ...