spring使用ExcludeFilter和IncludeFilter
使用IncludeFilter。就算目标类上没有@Component注解,它也会被扫描成为一个Bean
@ComponentScan(value = "com.yzy", includeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {OtherEntity.class})}) @MapperScan(basePackages = "com.yzy.springdemo.dao") @EnableAspectJAutoProxy public class SpringAnnotationTest {}
public class OtherEntity {}
public class Test {public static void main(String[] args) throws IOException {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringAnnotationTest.class);OtherEntity otherEntity = (OtherEntity) context.getBean("otherEntity");System.out.println(otherEntity);//com.yzy.other.OtherEntity@5769e7ae} }
使用ExcludeFilter,就算目标类上面有@Component注解也不会成为Bean
@Component public class OtherEntity {}
@ComponentScan(value = "com.yzy",excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {OtherEntity.class})}) @MapperScan(basePackages = "com.yzy.springdemo.dao") @EnableAspectJAutoProxy public class SpringAnnotationTest {}
public class Test {public static void main(String[] args) throws IOException {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringAnnotationTest.class);OtherEntity otherEntity = (OtherEntity) context.getBean("otherEntity");System.out.println(otherEntity);} }
运行项目:
spring使用ExcludeFilter和IncludeFilter相关推荐
- spring中的context:include-filter和context:exclude-filter的区别
http://blog.csdn.net/w2393040183/article/details/50749851 <!-- 扫描@Controller注解 --><context: ...
- Spring框架使用规范和IOC的开发
Spring框架是一个管理对象的容器,就像Web容器Tomcat可以管理servlet的生命周期,Spring容器可以管理对象的生命周期. Spring的组件化让类和类对象之间的关系变得不那么紧密,降 ...
- spring component-scan filter
(参考的Spring version : 4.1.6.RELEASE) 我们通常会使用component-scan来进行bean的加载,但是它里面的实现机制却是一知半解.根据原码来理解一下,可能会更加 ...
- SpringMVC(2)—SpringMVC整合Spring的HelloWorld
一.这是一个SpringMVC框架的案例HelloWorld 功能:HelloWorld 二.SpringMVC运行流程 1.流程 请求-->springDispatcherServlet的ur ...
- 关于Spring注解开发教程,打包全送你
摘要:spring是我们web开发中必不可少的一个框架,基于传统的xml方式配置bean总觉得太过繁琐,从spring2.5之后注解的出现可以大大简化我们的配置. 本文分享自华为云社区<如何高效 ...
- 【Java从0到架构师】Spring - 纯注解开发
纯注解开发 纯注解开发 - AOP 纯注解开发 - 整合 MyBatis 纯注解开发 - 事务管理 JSR 注解 JSR 注解 - @Resource.@Inject JSR 注解 - @PostCo ...
- 【Spring】context:component-scan包扫描问题
Spring 项目bean 无法注入或者初始化,可能是扫描问题,下面分两种情况研究 1.配置的bean 没有被扫描 先说一下<context:component-scan base-packag ...
- spring(春天)
目录 spring案例 spring优点 组成 引入基础jar包 IOC理论 IOC容器--Bean管理xml的方式 什么是bean管理? IOC操作Bean管理两种方式(创建类和注入属性的方式) I ...
- Spring源码学习(三)-- 底层架构核心概念解析
前面,我们大概了解了Spring中的一些概念和底层工作流程,这篇是后续看Spring源码所必备的,防止后续看源码的过程中,遇到不会的概念得单独跳出来学习. BeanDefinition BeanDe ...
最新文章
- leetcode - 467. 环绕字符串中唯一的子字符串
- linux安装nsenter工具,Docker 使用nsenter工具进入容器的操作
- Service服务Android
- 四级过了,我却高兴不起来!
- PMP考试真题模拟PMP考试模拟试题及答案详解
- 裂变新玩法 2022年京东双十一红包如何领取?
- Java+PDFBox将PDF转成图片
- TweenMax之一些方法
- 银河麒麟 安装PL2303GC USB转串口驱动
- python excel动态图表_那些年做过的动态图表-实用漂亮的Excel动态图表
- 网易云音乐API,的调用方法 ,vue项目中(在本地使用)
- 中国民营医院行业市场运营模式与发展动向展望报告2022~2027年
- SublimeLinter进行PHP代码检查
- 【论文阅读】Learning Deep Features for Discriminative Localization
- 鼠标每隔几秒失去焦点,鼠标每隔几秒转圈,鼠标每隔几秒刷新
- 【NRF51822】百度手环开源源码分析--底层通讯部分
- 阿里云呼叫中心发布,为企业提供更灵活可靠的热线服务
- chariot iperf使用_jperf使用说明
- Qt 窗口操作函数(置顶、全屏,最大化最小化按钮设置等)
- 2022-2028全球类脑智能芯片行业调研及趋势分析报告
热门文章
- Vue项目之上传图片
- 白领的一天 场景7:薪水与福利
- 浏览器放大缩小,页面布局不变,浏览器放大百分比,页面放大到左上角,浏览器缩小百分比,页面缩小至中间(类似csdn官网效果)
- 给定连接查询ems配送信息
- iPhone4S大跌4000港元成跌价王 水货商谨慎进货
- mysql 8安装方法_Mysql8.0.17安装教程【推荐】
- c语言程序设计基础广西师范大学出版社答案,附录Ⅰ全国高校计算机等级考试广西考区二级考试大纲.DOC...
- 安全工具-curl学习
- 每日一词20190316——GIS矢量数据和栅格数据对比
- TIP 2021 | 重访CV经典!首个无监督深度学习图像拼接框架