报错信息:

2019-04-01 14:33:10.703 ERROR 1957 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@517a46f3] to prepare test instance [com.****.account.controller.CpsAccountLogControllerUnitTest@377e90b0]java.lang.IllegalStateException: Failed to load ApplicationContextat org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) ...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cpsSettlementMapper' defined in URL [jar:file:/Users/pilaf/IdeaProject/hydra/hydra-dao/target/hydra-dao-0.0.1-SNAPSHOT.jar!/com/**/mapper/CpsSettlementMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are requiredat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]...
Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are requiredat org.springframework.util.Assert.notNull(Assert.java:198) ...[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.626 s <<< FAILURE! - in com.****.account.controller.CpsAccountLogControllerUnitTest
[ERROR] testInsert(com.****.account.controller.CpsAccountLogControllerUnitTest)  Time elapsed: 0.004 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cpsSettlementMapper' defined in URL [jar:file:/Users/pilaf/IdeaProject/hydra/hydra-dao/target/hydra-dao-0.0.1-SNAPSHOT.jar!/com/**/mapper/CpsSettlementMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

解决方式是在项目依赖中加入:

<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter-test</artifactId><version>1.3.2</version>
</dependency>

这个依赖信息在文章最后参考网址1中有说明。

然后在单元测试类上面加上
org.mybatis.spring.boot.test.autoconfigure.AutoConfigureMybatis注解:

@ActiveProfiles("staging")
@RunWith(SpringRunner.class)
@AutoConfigureMybatis
@WebMvcTest(CpsAccountLogController.class)
public class CpsAccountLogControllerUnitTest {....
}

参考网址:
1.http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-test-autoconfigure/
2.https://github.com/mybatis/spring-boot-starter/issues/227

springboot+mybatis打包时,单元测试类报错相关推荐

  1. 关于webpack打包时less-loder安装报错处理

    关于webpack打包时less-loder安装报错 loadercontext.getresolve is not a function 需要换低版本的less-loader 在package.js ...

  2. vue-cli打包构建时常见的报错解决方案

    vue-cli打包构建时常见的报错解决方案 参考文章: (1)vue-cli打包构建时常见的报错解决方案 (2)https://www.cnblogs.com/bester-ace/articles/ ...

  3. springBoot启动类报错

    关于SpringBoot启动类报错的问题解决: APPLICATION FAILED TO START Description: Field elasticsearchRestTemplate in ...

  4. Springboot项目常见的8个报错

    Springboot项目常见的8个报错 1.500状态码: 代表服务器业务代码出错,也就是执行Controller里面的某个方法的过程中报错, 此时在idea的控制台中会显示具体的错误信息, 所以需要 ...

  5. java使用cmd编译中文时错误,解决Notepad++编写的Java程序在cmd窗口编译时中文注释报错问题...

    解决Notepad++编写的Java程序在cmd窗口编译时中文注释报错问题 解决Notepad++编写的Java程序在cmd窗口编译时中文注释报错问题 在刚开始学习Java的过程中,考虑到记事本应用没 ...

  6. 上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间

    1. 问题 SpringBoot上传文件时,服务器报错 2022-06-27 10:58:00.941 ERROR 12700 --- [nio-8900-exec-1] o.a.c.c.C.[.[. ...

  7. Qt使用导出类报错:error C2491: “LmcThreadPaddle::staticMetaObject”: 不允许 dllimport 静态数据成员 的定义

    Qt使用导出类报错:error C2491: "LmcThreadPaddle::staticMetaObject": 不允许 dllimport 静态数据成员 的定义 在使用继承 ...

  8. Nacos学习日记6-基于Springboot框架的Nacos服务注册报错:Application run failed

    目录 问题现象: 原因分析: 解决方法: 关于Curl的相关信息,想了解的同学可以查看我的其他文章,传送门: 问题现象: 今天在测试使用Nacos进行纯代码的方式去注册服务的时候,在启动项目时出现了报 ...

  9. jhipster修改jdl生成的实体类报错:liquibase.exception.ValidationFailedException: Validation Failed

    使用jhipster创建一个实体类之后,发现实体类不满足业务需求,需要修改: 如果是使用jdl创建的,那么我们只需要在原先的.jh文件中修改实体类内容,然后在项目根目录下执行命令: jhipster ...

最新文章

  1. SQL数据分析概览——Hive、Impala、Spark SQL、Drill、HAWQ 以及Presto+druid
  2. 程序猿段子_【新年新气象】今年,能为程序员男友做点什么?
  3. 如何在outlook里显示自然周的周数
  4. SAP云平台上的502 Bad Gateway错误
  5. java 文件编码 查询系统_javaweb垃圾分类查询系统、ssm+mysql
  6. 解决若干WTL与VS2010的兼容问题(如error MSB6006: “cmd.exe”)
  7. 易懂分布式 | Kademlia算法
  8. CentOS7中的firewall 和 iptables
  9. Android HandlerThread和IntentService
  10. 轻松搞定技术面系列 1——基础篇
  11. python 多线程伪_Python每日3题什么是死锁?
  12. Python天气查询系统(连接数据库版)
  13. 学计算机穿格子衬衫的男人,教你成为穿格子衬衫的帅气理工男
  14. 2022谷粒商城学习笔记(二十五)支付宝沙箱模拟支付
  15. centos7磁盘分区格式化
  16. 2020云服务平台领域最具商业合作价值企业盘点
  17. STM32L0外接32768HZ晶振应该接多大的负载电容才合适
  18. 立方尾不变-Python
  19. @Cacheable注解属性介绍
  20. fastboot常用指令

热门文章

  1. Espresso自动化测试(十一) - IdlingResource
  2. python语言程序设计习题
  3. 近一个月总结(鸡汤多于技术)
  4. oracle10G 异构方式迁移表空间之一
  5. 遇见未来 | 对话朱贤文,PostgreSQL是一匹即将发力的黑马
  6. JS基础之数组--概述、创建数组的几种方式、数组的特点、数组的常用方法、数组的解构赋值、数组高级API
  7. spring boot读取resources下面的文件图片
  8. Unity 父子约束 手持弓箭
  9. 超多版式运用手法!128张让你灵感爆发的海报设计
  10. hangfire mysql_.NET之Hangfire快速入门和使用