Spring 单元测试 RequestContextHolder.getRequestAttributes()).getRequest(); 为空的原因


原因是因为单元测试时没有加载 web.xml 中的:

复制代码
    <!-- spring在service层获取session和request需要创建的监听器 -->
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
复制代码

 

所以单元测试时如果需要用到 request 中的值的话,就用静态测试数据测试就好了~


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM