<?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 setting useDefaultFilters=false on the annotation or providing use-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.

最新文章

  1. AgileEAS.NET SOA 中间件Web运行容器管理功能已全部开源,欢迎大家下载、使用、反馈
  2. Request.UrlReferrer
  3. android 股票数据通过日K获取周K的数据 算法 源码
  4. js实现冒泡排序
  5. Q_INIT_RESOURCE宏
  6. JS倒计时器一只,顺便复习javascript时间相关函数
  7. apt-key adv
  8. View Components as Tag Helpers,离在线模板编辑又进一步
  9. 【SpringMVC】【EasyUI】关于使用EasyUIForm上传文件,返回JsonIE提示下载文件的解决办法!
  10. Docker(七):Docker容器卷管理
  11. map集合的常用方法
  12. Foxmail设置IMAP和STMP服务器
  13. Android 开发 Fresco框架点击小图显示全屏大图实现 ZoomableDraweeView
  14. js float运算精度问题
  15. maven3.5.0在win10中的安装及环境变量配置
  16. [leetcode]239. Sliding Window Maximum滑动窗口最大值
  17. INNER JOIN与LEFT JOIN在SQL Server的性能
  18. 20155214 2016-2017-2 《Java程序设计》第10周学习总结
  19. 如何用nodejs 开发一个命令行交互工具
  20. Mysql定时备份数据脚本

热门文章

  1. Google Closure Compiler 高级模式及更多思考(转)
  2. bzoj 1059: [ZJOI2007]矩阵游戏【匈牙利算法】
  3. 10.16NOIP模拟赛
  4. poj2096Collecting Bugs(概率期望dp)
  5. event.target 属性返回哪个 DOM 元素触发了事件。
  6. dos 下小tip
  7. jQuery学习笔记(2)-选择器的使用
  8. servlet下的request&amp;&amp;response
  9. Redis远程连接
  10. CF798C Mike and gcd problem