zoukankan      html  css  js  c++  java
  • srping mvc 集成CXF 导致类初始化两遍

    cxf依赖于spring的ContextLoaderListener,而spring mvc 则依赖于DispatcherServlet。

    初始化DispatcherServlet的时候会依赖初始化一个spring 容器,此容器为spring全局容器WebApplicationContext的子容器,如果调用相同的配置文件初始化将导致所有类初始化两次,造成不确定的错误。

    spring的字容器可以访问父容器内的对象,既然如此,可以让全局容器加载除Controller层以外的类,而让spring mvc容器加载Controller层的类,来解除此问题。

    具体配置实现:

    全局spring包扫描配置:

    <context:component-scan base-package="com.blackbread">
            <!-- 不加载org.springframework.stereotype.Controller类型注解 -->
            <context:exclude-filter type="annotation"
                expression="org.springframework.stereotype.Controller" />
        </context:component-scan>

    spring mvc 包扫描配置:

    <context:component-scan base-package="com.blackbread"
            use-default-filters="false">
            <!-- 只载org.springframework.stereotype.Controller类型注解 -->
            <context:include-filter type="annotation"
                expression="org.springframework.stereotype.Controller" />
        </context:component-scan>

    在web.xml中分别加载不同的配置文件,即可解决所有类加载两遍问题。

  • 相关阅读:
    四则运算测试脚本运行情况
    AAA
    (2015秋) 软工作业成绩公布(12月26号更新)
    判断闰年的Java算法
    B
    A
    Where Amazing Happens
    安利一发资料站
    C
    B
  • 原文地址:https://www.cnblogs.com/lcxdever/p/3915236.html
Copyright © 2011-2022 走看看