1.applicationContext.xml
<!--注解说明 -->
<context:annotation-config />
<!-- 把标记了@Controller注解的类转换为bean -->
<context:component-scan base-package="cn.godzilla" >
<context:[b]exclude[/b]-filter type="regex" expression="cn.godzilla.web.*"/>
</context:component-scan>
2.springmvc-servlet.xml
<!--注解说明 -->
<context:annotation-config />
<!-- 把标记了@Controller注解的类转换为bean -->
<context:component-scan base-package="cn.godzilla" >
<context:[b]include[/b]-filter type="regex" expression="cn.godzilla.web.*"/>
</context:component-scan>
<!--注解说明 -->
<context:annotation-config />
<!-- 把标记了@Controller注解的类转换为bean -->
<context:component-scan base-package="cn.godzilla" >
<context:[b]exclude[/b]-filter type="regex" expression="cn.godzilla.web.*"/>
</context:component-scan>
2.springmvc-servlet.xml
<!--注解说明 -->
<context:annotation-config />
<!-- 把标记了@Controller注解的类转换为bean -->
<context:component-scan base-package="cn.godzilla" >
<context:[b]include[/b]-filter type="regex" expression="cn.godzilla.web.*"/>
</context:component-scan>
Spring MVC注解配置详解
本文深入探讨了Spring MVC中ApplicationContext.xml和springmvc-servlet.xml文件的注解配置,包括如何使用@ContextConfiguration注解加载配置类,以及如何通过@ComponentScan进行组件扫描,排除特定包下的组件,并仅包含特定路径下的组件。
1万+

被折叠的 条评论
为什么被折叠?



