当前位置:网站首页>通过@Autowired注入的bean,即使这个类上没有标注@Comment等这一类的注解,但是这个bean依然能够注入进来
通过@Autowired注入的bean,即使这个类上没有标注@Comment等这一类的注解,但是这个bean依然能够注入进来
2022-07-22 10:32:00 【dotaer-df】
问题描述:在公司的项目中进行单元测试的时候发现,即使这个类上没有标注@Comment或者@Service等这一类的注解,但是Bean依然能够注入进来。
按理说springboot在进行扫描的时候,没有标注注解的类是不会加载到ioc容器里面,就很奇怪。因为常见注入类到ioc容器中,无非通过注解和xml,注解没配置,那应该就是通过xml实例化了,经过排查发现,在启动类中通过@ImportResource导入了xml文件applicationContext.xml在这个xml中有这样一段配置
<context:component-scan base-package="com.xxx.xxx">
<context:include-filter type="aspectj"
expression="com.xxx.xxx..impl..*BOImpl"/>
<context:include-filter type="aspectj"
expression="com.xxx.xxx..impl..*ServiceImpl"/>
</context:component-scan>
context:include-filter过滤器有五种type:
assignable-指定扫描某个接口派生出来的类
annotation-指定扫描使用某个注解的类
aspectj-指定扫描AspectJ表达式相匹配的类
custom-指定扫描自定义的实现了org.springframework.core.type.filter.TypeFilter接口的类
regex-指定扫描符合正则表达式的类
所以在当前expression设置的路径下的类都会自动注入到容器中
边栏推荐
猜你喜欢
Getting started with CSDN markdown editor
什么是百度快照劫持?百度快照劫持原理和解决办法
Her power series II UCLA Li Jingyi: the last thing women need to do is "doubt themselves"
网站安全之域名被劫持、域名被劫持后该怎么办!!!
How to solve the blue screen problem in win8.1 system and how to solve the malicious hijacking of IE home page?
Classic cases of semaphore synchronization and mutual exclusion
RAG小结
她力量系列三丨把握当下,坚持热爱,与食物图像识别结缘的科研之路
Plug in installation of elastic search getting started (5)
Chinese search for introduction to elastic search (8)
随机推荐
Dense Passage Retrieval for Open-Domain Question Answering笔记
Leetcode 300. longest increasing subsequence
LeetCode0003——longest substring without repeating characters——Sliding Window
druid加密命令
《预训练周刊》第39期: 深度模型、提示学习
linux安装oracle XE
What are the common ways for websites to be hacked and hijacked? What are the DNS hijacking tools?
vim 使用tips
IDEA 隐藏.idea文件夹 隐藏.iml文件
LeetCode0022——括号生成——DFS
How to prevent DNS hijacking and what is DNS? DNS hijacking details
Introduction to machine learning: Logistic regression-2
win8.1系统发生蓝屏问题解决方法、IE主页被恶意劫持怎么解决?
JNI 数据类型用法
flask 跨域
机器学习入门:逻辑回归-2
Plug in installation of elastic search getting started (5)
Common tools for data development - regular sending of query results email
How to deal with DNS hijacked? Five ways to deal with it
Easy operation commands of ES for getting started with elastic search (II)