SpringMVC中的两个标签context:include-filter和context:exclude-filter

Spring、SpringMVC的配置文件

本人是个菜鸟,只是写我遇到的,我觉得怎样怎样的,我个人怎么理解的(我感觉我撒也不会)。

问题阐述:为何会有两个配置文件 两个配置文件都配置了

<context:component-scan base-package=“com.hjcrm”>

web.xml是这样配置的(我直接取这一部分):

 <!--加载spring配置文件-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!--加载springMVC配置文件-->
    <servlet>
        <servlet-name>crm</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:context-dispatcher.xml</param-value>
        </init-param>
        <!--启动容器,即加载配置文件(防止遗漏)-->
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!--请求后缀-->
    <servlet-mapping>
        <servlet-name>crm</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

applicationContext.xml中的配置:

 <context:component-scan base-package="com.hjcrm">
        <!--将Controller的注解排除掉 -->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
 </context:component-scan>

context-dispatcher.xml的配置

 <context:component-scan base-package="com.hjcrm.**.controller" >
        <!--使用注解的包,包括子集-->
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />  
 </context:component-scan>

也是从别人的博客了解到,得到的结果是:
这是将他们分开配置,就好像解耦一样,让两个配置文件各司其职,各管各的模块,能够分工明确,context-dispathcer更是只处理controller的内容,对于代码的编写来说更加的好理解,更清晰!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值