第一章 Spring中组件扫描
1.1 默认使用情况
<context:component-scan base-package="com.atguigu"></context:component-scan>
1.2 包含扫描
- 注意:
- 使用包含扫描之前,必须设置use-default-filters=“false”【关闭当前包及其子包的扫描】
- type
- annotation:设置被扫描注解的全类名
- assignable:设置被扫描实现类的全类名
<context:component-scan base-package="com.atguigu" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:include-filter type="assignable" expression="com.atguigu.service.impl.DeptServiceImpl"/>
</context:component-scan>
1.3 排除扫描
<context:component-scan base-package="com.atguigu">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>