springboot 测试 有注入HttpSession的bean
question:
nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
solution:
RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest()));
springboot 测试 有注入HttpSession的bean的更多相关文章
- spring springboot websocket 不能注入( @Autowired ) service bean 报 null 错误
spring 或 springboot 的 websocket 里面使用 @Autowired 注入 service 或 bean 时,报空指针异常,service 为 null(并不是不能被注入). ...
- Springboot 测试类没有找到bean注入
其他乱七八糟配置就不扯了,先上项目结构图 配置好参数后我再src/test/java类测试访问数据库时发现bean没有正确的注入.值得注意的是,这个项目的启动类是叫App.java 所以我们必须在这个 ...
- SpringBoot集成spring-data-jpa注入Bean失败
当项目结构正常(spring管理的Bean在SrpingBoot启动类平级或下级,支持spring扫描时),实现类上加 @Service注解,在实现类中注入dao层的Bean时,项目无法启动,无法找到 ...
- 【spring set注入 注入集合】 使用set注入的方式注入List集合和Map集合/将一个bean注入另一个Bean
Dao层代码: package com.it.dao; public interface SayHell { public void sayHello(); } Dao的Impl实现层: packag ...
- springboot测试、打包、部署
本文使用<springboot集成mybatis(一)>项目,依次介绍springboot测试.打包.部署. 大多数朋友是做后端的,也就是为其他系统或者前端UI提供Rest API服务. ...
- Spring boot 将配置文件属性注入到一个bean中
现在要做的就是将如下配置文件中的内容注入到一个bean 名为Properties中. Redis.properties配置文件中的内容如下: Properties java bean中代码如下,注意注 ...
- 正确理解springboot的常用注入方式
springboot的属性注入 以注入dataSource为例1.springboot默认读取的文件是放在resources目录下的名为application.properties或applicati ...
- spring练习,使用Eclipse搭建的Spring开发环境,使用set注入方式为Bean对象注入属性值并打印输出。
相关 知识 >>> 相关 练习 >>> 实现要求: 使用Eclipse搭建的Spring开发环境,使用set注入方式为Bean对象注入属性值并打印输出.要求如下: ...
- 深入理解springboot的自动注入
一.开篇 在平时的开发过程中用的最多的莫属springboot了,都知道springboot中有自动注入的功能,在面试过程中也会问到自动注入,你知道自动注入是怎么回事吗,springboot是如何 ...
随机推荐
- Day41 openstack基础
参考博客: http://www.cnblogs.com/linhaifeng/p/6264636.html
- PHP:第五章——字符串与数组及其他函数
<?php header("Content-Type:text/html;charset=utf-8"); //1.str_split——将字符串转换为数组. /*$str= ...
- Laravel框架中Validor中错误信息$error的输出
@if (count($errors) > 0) <div class="alert alert-danger"> <ul> @foreach ($e ...
- PHP:第五章——字符串编码函数
<?php header("Content-Type:text/html;charset=utf-8"); //1.base64_encode和base64_decode.6 ...
- android中string.xml中%一$s、%1$d等的用法
%n$ms:代表输出的是字符串,n代表是第几个参数,设置m的值可以在输出之前放置空格 %n$md:代表输出的是整数,n代表是第几个参数,设置m的值可以在输出之前放置空格,也可以设为0m,在输出之前放置 ...
- SSH使用主机名访问
比如说A电脑已经和B电脑实现了ssh免密码登陆!但是A电脑通过 ssh B电脑的主机名称 不行! 解决办法: 01.修改A电脑中的hosts文件 vim /etc/hosts 02.进入编辑界面 ...
- Python3 字符串(七)
字符串是 Python 中最常用的数据类型.我们可以使用引号( ' 或 " )来创建字符串. 创建字符串很简单,只要为变量分配一个值即可. python中单引号和双引号使用完全相同. 使用三 ...
- Toncat-OpenSSL双向认证配置(iOS)
OpenSSL生成证书 要生成证书的目录下建立几个文件和文件夹,有./demoCA/ ./demoCA/newcerts/ ./demoCA/private/ ./demoCA/index.txt ( ...
- java回收finalize方法的作用(编程思想)
清理:终结处理和垃圾回收 java有垃圾回收期负责回收无用对象占据的内存资源.但也有这种情况:假定你的对象(并非使用new)获得了一块“特殊”的内存区域,由于垃圾回收期只知道释放那些由new分配的内存 ...
- prototype原型模式
/** * 原型模式 Prototype * 用原型实例指定创建对象的种类,并通过拷贝这些原型创建新的对象 */ 需求: public class Resume { /** * 要求:一个简历类,必须 ...