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的更多相关文章

  1. spring springboot websocket 不能注入( @Autowired ) service bean 报 null 错误

    spring 或 springboot 的 websocket 里面使用 @Autowired 注入 service 或 bean 时,报空指针异常,service 为 null(并不是不能被注入). ...

  2. Springboot 测试类没有找到bean注入

    其他乱七八糟配置就不扯了,先上项目结构图 配置好参数后我再src/test/java类测试访问数据库时发现bean没有正确的注入.值得注意的是,这个项目的启动类是叫App.java 所以我们必须在这个 ...

  3. SpringBoot集成spring-data-jpa注入Bean失败

    当项目结构正常(spring管理的Bean在SrpingBoot启动类平级或下级,支持spring扫描时),实现类上加 @Service注解,在实现类中注入dao层的Bean时,项目无法启动,无法找到 ...

  4. 【spring set注入 注入集合】 使用set注入的方式注入List集合和Map集合/将一个bean注入另一个Bean

    Dao层代码: package com.it.dao; public interface SayHell { public void sayHello(); } Dao的Impl实现层: packag ...

  5. springboot测试、打包、部署

    本文使用<springboot集成mybatis(一)>项目,依次介绍springboot测试.打包.部署. 大多数朋友是做后端的,也就是为其他系统或者前端UI提供Rest API服务. ...

  6. Spring boot 将配置文件属性注入到一个bean中

    现在要做的就是将如下配置文件中的内容注入到一个bean 名为Properties中. Redis.properties配置文件中的内容如下: Properties java bean中代码如下,注意注 ...

  7. 正确理解springboot的常用注入方式

    springboot的属性注入 以注入dataSource为例1.springboot默认读取的文件是放在resources目录下的名为application.properties或applicati ...

  8. spring练习,使用Eclipse搭建的Spring开发环境,使用set注入方式为Bean对象注入属性值并打印输出。

    相关 知识 >>> 相关 练习 >>> 实现要求: 使用Eclipse搭建的Spring开发环境,使用set注入方式为Bean对象注入属性值并打印输出.要求如下: ...

  9. 深入理解springboot的自动注入

    一.开篇   在平时的开发过程中用的最多的莫属springboot了,都知道springboot中有自动注入的功能,在面试过程中也会问到自动注入,你知道自动注入是怎么回事吗,springboot是如何 ...

随机推荐

  1. 探索解析微服务下的RabbitMQ

    概览 本文主要介绍如何使用RabbitMQ消息代理来实现分布式系统之间的通信,从而促进微服务的松耦合. RabbitMQ,也被称为开源消息代理,它支持多种消息协议,并且可以部署在分布式系统上.它轻量级 ...

  2. 【源码学习之spark core 1.6.1 standalone模式下的作业提交】

    说明:个人原创,转载请说明出处 http://www.cnblogs.com/piaolingzxh/p/5656876.html 未完待续

  3. mong大牛的blog

    MongoDB权威指南(3)-查询1.find方法介绍在不传入参数的情况下,find方法缺省使用  http://www.educity.cn/wenda/389594.html 这个归纳的比较好:可 ...

  4. 转:Tomcat 7.0配置SSL的问题及解决办法

    原文:https://dong-shuai22-126-com.iteye.com/blog/1830209

  5. type使用细则

    CREATE OR REPLACE TYPE ADDRESS_TYPE   --创建类型 ADDRESS_TYPE AS OBJECT(ZIP VARCHAR2(6),PROVINCE VARCHAR ...

  6. E: 无法获得锁 /var/cache/apt/archives/lock - open (11 资源临时不可用)

    事件: 今软件包有更新,进入更新管理器,点击安装更新,出现错误. 错误提示: E: 无法获得锁 /var/cache/apt/archives/lock - open (11 资源临时不可用) E: ...

  7. java 8 日期api

    //localdatetime -> string LocalDateTime now = LocalDateTime.now(); String format = now.format(Dat ...

  8. Git观察和比较

    log git log 时间是从下到上,从远到近   whatchanged git whatchanged 时间是从下到上,从远到近   diff --staged 比较工作区和缓存区之间的差异 g ...

  9. 从U-Boot显示Logo到Android

    /******************************************************************************* * 从U-Boot显示Logo到And ...

  10. mac终端下修改MySQL的编码格式--找不到my-default.cnf及my.cnf

    首先请确认正确安装好MySQL. 1- 先配置环境变量path 1.1 打开终端,输入: cd ~ 会进入~文件夹, 1.2 然后输入:touch .bash_profile 回车执行后, 1.3 再 ...