美文网首页
Spring 4.0 StandaloneMockMvcBuil

Spring 4.0 StandaloneMockMvcBuil

作者: coder豪 | 来源:发表于2017-01-02 23:29 被阅读37次

    原因分析:

    Spring4 与servlet2.5兼容性问题

    在 debug 模式下,可以知道 standaloneSetup(clrr) 得到的是 StandaloneMockMvcBuilder 对象和 exception 中报异常的类名一致。

    Cannot create MockHttpSession with servlet 2.x, spring得到下面有用提示:Spring 4.0 需要得到 servlet 3.0 或以上版本的支持。

    The Servlet API mocks in Spring Framework 4.0 support Servlet 3.0 and higher, as can be seen inGitHub commit deba32cad9.

    追踪上面的 github 链接,可以发现 SessionCookieConfig 是在升级 servlet API 到 3.0 变动中新增的。

    在查询SessionCookieConfig 文档,可以知道 SessionCookieConfig 是在 servlet 3.0 才引入的。

    解决方案:

    pom.xml中添加servlet 3.0.1, artifactId为javax.sevlet-api

    注意:artifactId
    原本2.5版本的是servlet-api

    3.0.1版本的是javax.sevlet-api

    相关文章

      网友评论

          本文标题:Spring 4.0 StandaloneMockMvcBuil

          本文链接:https://www.haomeiwen.com/subject/bzrgvttx.html