junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题,说明代码是没问题的,配置也没问题。开始时怀疑是我使用junit版本的问题,于是换版本,不管用;甚至一度怀疑是不是我的myeclipse没破解好,一度有卸了重装的冲动。其实都没问题,点击myeclipse最上面的project——————>clean------->勾选你的项目--------->ok;(注意不是右键maven clean),然后再测试就没问题了,我也不知道为啥,感觉好奇葩,莫名其妙

错误信息如下:

java.lang.IllegalStateException: Failed to load ApplicationContext
 at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
 at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
 at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
 at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
 at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
 at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
 at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public slc.dao.TestUserMapper slc.service.impl.UserServiceImpl.testUserMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [slc.dao.TestUserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testRoleMapper' defined in file [D:\ProgramFiles\myeclipse2014\slcprojects\NongyeInfo\target\classes\slc\dao\TestRoleMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:slc/mapping/*.xml]: class path resource [slc/mapping/] cannot be resolved to URL because it does not exist
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testUserMapper' defined in file [D:\ProgramFiles\myeclipse2014\slcprojects\NongyeInfo\target\classes\slc\dao\TestUserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:slc/mapping/*.xml]: class path resource [slc/mapping/] cannot be resolved to URL because it does not exist
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
 at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
 at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
 at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
 at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
 at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
 at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
 ... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public slc.dao.TestUserMapper slc.service.impl.UserServiceImpl.testUserMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [slc.dao.TestUserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
 ... 41 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [slc.dao.TestUserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
 ... 43 more

转载于:https://www.cnblogs.com/mengjinluohua/p/5416973.html

junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题...相关推荐

  1. Junit单元测试报错Class not found可能原因

    Junit单元测试报错Class not found可能原因 1.将maven的后台运行关闭 2.Test方法中的语法错误

  2. windows 打开PyCharm报错failed to load JVM DLL pycharm\jbr\\bin\server\jvm.dll

    windows 打开PyCharm报错failed to load JVM DLL pycharm\jbr\bin\server\jvm.dll jdk下载安装成功,环境变量配置成功 解决办法:PyC ...

  3. U盘装Ubuntu系统报错Failed to load ldlinux.c32

    U盘装Ubuntu系统报错Failed to load ldlinux.c32 可能是两种原因导致的,可以进行排查 1.镜像文件问题 2.刻录软件的问题 1.镜像文件 如果报此类错误,有可能是镜像文件 ...

  4. jupyter notebook报错Failed to load module appmenu-gtk-module

    完整报错如下: Gtk-Message: 09:20:49.827: Failed to load module "appmenu-gtk-module" Gtk-Message: ...

  5. mesos-master启动失败,报错Failed to load unknown flag 'quorum.rpmsave'

    [现象] mesos启动失败,查看mesos状态报错: [root@hps102 ~]# systemctl status mesos-master ● mesos-master.service - ...

  6. Vue 打包后打开为空白页面 并且控制台报错‘Failed to load resource: net::ERR_FILE_NOT_FOUND’

    当我们开发完成后进行 npm run build打包后形成dist文件 我们通过访问dist文件中的index,会出现空白页面什么都不显示的问题,控制台中还会报'Failed to load reso ...

  7. [雷]单元测试报错--Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test

    项目场景: SpringBoot集成Mybatis-Plus时,进行单元测试时报错 问题描述: package com.mybatisplusstudty.mapper;import org.juni ...

  8. junit单元测试报错InvalidTestClassError: Invalid test class

    观察Failure Trace的报错信息,我这边显示的是test should be public ,说明是我格式错了用了void而不是public void .

  9. junit 单元测试报错java.lang.NoClassDefFoundError

    查看版本 junit-4.11以上版本不在包含hamcrest. 解决方法: 下载 junit-4.11以下版本或下载hamcrest-core-1.3.jar驱动包

  10. Android 报错Failed to load native library: XXXX_so

    产生原因: cpu架构不支持 so库没有打包到Android下 解决方案: 第一种可以通过命令adb shell cat /proc/cpuinfo 来查看cpu详细信息,排查架构不支持的问题 我这里 ...

最新文章

  1. Nginx+uWSGI+Django原理
  2. python 第三方登录_【Python web 开发】social_django 集成第三方登录
  3. batch spring 重复执行_可能是最漂亮的Spring事务管理详解
  4. @程序员,多写点“坏”代码吧!
  5. 智乃的01串打乱(思维+暴力)
  6. syslog工具_INAV:一款专用的日志审查导航工具
  7. python 爬虫系列之极验滑块打码
  8. NanoDet代码逐行精读与修改(四)动态软标签分配:dynamic soft label assigner
  9. 关于VS2010下编译NTL库方法及NTL库的应用
  10. 低碳世界杂志低碳世界杂志社低碳世界编辑部2022年第7期目录
  11. 重来之大学版|社交生活篇——失恋了怎么办?失恋了很难受怎么办?如何走出失恋的痛苦?我失恋了该怎么办?如何从失恋的痛苦中走出来?
  12. labelme 批量转换json文件 详细步骤
  13. python读取svg_使用Python / PIL读取SVG文件
  14. MATLAB中用李沙育图形分析光栅尺sincos信号正交性
  15. IIS写权限漏洞原理利用工具手动版
  16. juju based openstack upgrade (by quqi99)
  17. oh my posh安装(新版powerShell7/pwsh安装路径/oh my posh)
  18. Windows端iCloud现严重问题:显示陌生人照片和视频
  19. ppa:ondrej/php,现在为什么 Ubuntu ppa:ondrej/PHP 添加不了??
  20. 计算机设备管理器没有网络适配器,设备管理器没有网络适配器,小编教你Win7设备管理器中没有网络适配器如何恢复...

热门文章

  1. 职务作品的著作权归属情况分析
  2. LeetCode--026--删除排序数组中的重复项(java)
  3. 企业微信2.6.0发布 可与微信用户群聊了
  4. 通信业正面临一场巨变,要么滚蛋要么改变
  5. 手机团购,团购市场的下一引爆点
  6. 中国民间秘术大揭露【实用】
  7. 2018.10.04 NOIP模拟 航班(tarjan+树形dp)
  8. html+css笔记1
  9. Uva 11054 - Wine trading in Gergovia(模拟)
  10. 数据库 基础学习7— 数据库编程