<context:component-scan/> 配置项不但启用了对类包进行扫描以实施注释驱动 Bean 定义的功能,
同时还启用了注释驱动自动注入的功能
( 即还隐式地在内部注册了 AutowiredAnnotationBeanPostProcessor 和 CommonAnnotationBeanPostProcessor ),
因此当使用 <context:component-scan/> 后,就可以将 <context:annotation-config/> 移除了。
<context:component-scan/> 的 base-package 属性指定了需要扫描的类包,类包及其递归子包中所有的类都会被处理。
作用就是所有的 hibernate 配置都不用在 hibernate.cfg.xml 里配置了,也不用一大堆的像Employee.hbm.xml,Person.hbm.xml。
OVER!!!
本文详细介绍了Spring框架中<context:component-scan/>配置的作用,它不仅能够实现基于注释的Bean定义,还能自动启用@Autowired和@Qualifier等注解功能,简化Hibernate配置并减少XML配置文件。
648





