在context中配置
如:在base-package指明一個包:
<context:component-scan base-package="cn.edu.dao"/>
表明cn.gacl.java包及其子包中,如果某個類的頭上帶有特定的注解
@Component,@Repository,@Service,@Controller,就會将這個對象作為Bean注冊進Spring容器。
在<context:component-scan base-package=” ”/>中指定多個包:
<context:component-scan base-package="cn.edu.dao.impl,cn.edu.service.impl,cn.edu.action"/>
多個包逗号隔開。