Spring 使用注解注入 学习(四)
2024-09-08 02:24:31
<?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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="org.example"/> </beans>
@Configuration
@ComponentScan(basePackages = "org.example")
public class AppConfig {
...
}
The use of <context:component-scan> implicitly enables the functionality of <context:annotation-config>. There is usually no need to include the <context:annotation-config> element when using <context:component-scan>.
当在组件类上使用了特定的注解之后, 还需要在 Spring 的配置文件中声明 <context:component-scan> :
base-package 属性指定一个需要扫描的基类包,Spring 容器将会扫描这个基类包里及其子包中的所有类.
当需要扫描多个包时, 可以使用逗号分隔.
如果仅希望扫描特定的类而非基包下的所有类,可使用 resource-pattern 属性过滤特定的类,示例: <context:include-filter> 子节点表示要包含的目标类
<context:exclude-filter> 子节点表示要排除在外的目标类
<context:component-scan> 下可以拥有若干个 <context:include-filter> 和 <context:exclude-filter> 子节点 You can also disable the default filters by settinguseDefaultFilters=false
on the annotation or providinguse-default-filters="false"
as an attribute of the<component-scan/>
element. This will in effect disable automatic detection of classes annotated with@Component
,@Repository
,@Service
,@Controller
, or@Configuration
.
最新文章
- AgileEAS.NET SOA 中间件Web运行容器管理功能已全部开源,欢迎大家下载、使用、反馈
- Request.UrlReferrer
- android 股票数据通过日K获取周K的数据 算法 源码
- js实现冒泡排序
- Q_INIT_RESOURCE宏
- JS倒计时器一只,顺便复习javascript时间相关函数
- apt-key adv
- View Components as Tag Helpers,离在线模板编辑又进一步
- 【SpringMVC】【EasyUI】关于使用EasyUIForm上传文件,返回JsonIE提示下载文件的解决办法!
- Docker(七):Docker容器卷管理
- map集合的常用方法
- Foxmail设置IMAP和STMP服务器
- Android 开发 Fresco框架点击小图显示全屏大图实现 ZoomableDraweeView
- js float运算精度问题
- maven3.5.0在win10中的安装及环境变量配置
- [leetcode]239. Sliding Window Maximum滑动窗口最大值
- INNER JOIN与LEFT JOIN在SQL Server的性能
- 20155214 2016-2017-2 《Java程序设计》第10周学习总结
- 如何用nodejs 开发一个命令行交互工具
- Mysql定时备份数据脚本
热门文章
- Google Closure Compiler 高级模式及更多思考(转)
- bzoj 1059: [ZJOI2007]矩阵游戏【匈牙利算法】
- 10.16NOIP模拟赛
- poj2096Collecting Bugs(概率期望dp)
- event.target 属性返回哪个 DOM 元素触发了事件。
- dos 下小tip
- jQuery学习笔记(2)-选择器的使用
- servlet下的request&;&;response
- Redis远程连接
- CF798C Mike and gcd problem