1、spring配置文件如下
<context:component-scan base-package="com.hesvit">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
xml配置说明:
<context:component-scan/>
上下文组件扫描
1.1“com.hesvit”表示扫描com.hesvit包下的所有java类
1.2
<context:exclude-filter type="annotation"expression="org.springframework.stereotype.Controller" />
表示扫描com.hesvit包下的类,但排除@controller注解的
1.3 如果是 <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
表示扫描com.hesvit包下的只包含@controller注解的
1.4 context:component-scan中use-default-filters
在context:component-scan可以添加use-default-filters,spring配置中的use-default-filters用来指示是否自动扫描带有@Component、@Repository、@Service和@Controller的类。默认为true,即默认扫描。
###其他
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
的作用请参考以下链接:经常用于异常处理