一、自动扫描
使用Annotation自动注册Bean:在主容器中不扫描@Controller注解,在SpringMvc中只扫描@Controller注解。
1、spring配置文件(扫描注解)
<context:component-scan base-package="com.*.*"><!-- base-package 如果多个,用“,”分隔 --> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan>
2、springmvc配置文件(扫描注解)
<context:component-scan base-package="com.*.*"><!-- base-package 如果多个,用“,”分隔 --> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan>