Junit4测试错误解决java.lang.IllegalStateException: Failed to load ApplicationContext

SpringBoot项目JUnit单元测试运行报错-java.lang.IllegalStateException: Failed to load ApplicationContext SpringBoot项目JUnit单元测试运行报错一、问题描述二、报错信息三、报错原因四、解决办法 一、问题描述 问题描述: 写项目接口,在Junit单元测试中测试了ServiceImpl中的方法,此时的Controller层对外接口已经完成,但是在Junit方法Debug启动时,项目报错,在这里记录一下; 二、报错信息 报错信息: java.lang.IllegalStateExcept... 阅读详情
2013-09-22 15:51:42,000 ERROR (org.springframework.test.context.TestContextManager:315) - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1002a83] to prepare test instance [com.roc.ppms.test.dao.NewsDaoHibernateTest@1e70f62]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:313)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
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 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: com.roc.ppms.domain.NewsCol
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:106)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:57)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
... 24 more
Caused by: org.hibernate.MappingException: Association references unmapped class: com.roc.ppms.domain.NewsCol
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2503)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2782)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:65)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1423)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:720)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)

... 39 more


解决办法

按照xml文件加载顺序查找(例如ApplicationContext),最终找到是一个hbm.xml少写了个属性导致

Spring junit4单元测试出现异常:java.lang.IllegalStateException: Failed to load ApplicationContext Spring junit4单元测试出现异常:java.lang.IllegalStateException: Failed to load ApplicationContext 1 出错如下 [WARN ] 2019-03-06 14:13:36,077 method:org.springframework.context.support.AbstractApplicationContext.r... 阅读详情

相关推荐

软件工程:数据字典

数据字典

永远怀着至诚之心拥抱世界 4275

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘s

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory

qq_40834643的博客 5万+

树莓派3-改装wifi外置天线

声明:本文只是技术性探讨,改装引起的产品损坏等后果,由用户自负! 改装主要有两种方法 方法一:直接替换原来的天线 1、移除原有的小陶瓷天线,就在Made in PRC(或UK)那边的那个 清理一下阻焊剂方便天线接地(图中PRC左侧) 2、焊接天线 天线的屏蔽层焊接到清理完阻焊剂的地方,中间的信号线焊接到PRC右侧焊盘。 3、最终的样子

huayucong的博客 2万+

h2报错

2020-04-23 15:43:45.230 ERROR 3316 --- [ restartedMain] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. ...

一只小仙女的博客 1874

超详细Tokenizer——文本训练数据预处理

Tokenizer是Keras库中的一个文本处理工具,它用于将文本分词并构建词汇表,同时将文本映射到整数序列。这对于自然语言处理任务非常有用,例如文本分类、情感分析、机器翻译等。

halo的博客 3701

YALMIP介绍及怎么在Matlab中加YALMIP、SDPT3

目录YALMIP简介怎么在Matlab中加YALMIP?1. 创建决策变量:2. 添加约束:3. 参数配置4. 求解怎么在MatlabR2019a中加YALMIP?1.下载工具包2.放置工具包3.添加路径4.测试安装结果怎么在MatlabR2019a中加SDPT3? YALMIP简介 怎么在Matlab中加YALMIP? yalmip是一位“集大成者”,它不仅自己包含基本的线性规划求解算法,比如linprog(线性规划)、bintprog(二值线性规划)、bnb(分支界定算法)等,他还提供了对cpl

m0_51431440的博客 2万+

报错:Caused by org.springframework.beans.factory.BeanCreationException

【代码】报错:Caused by org.springframework.beans.factory.BeanCreationException。

m0_67390969的博客 1万+

与本地电脑PDF文档对话的PDF问答程序

紧接着,从PDF文档中提取文本,这部分代码的作用是遍历PDF文档中的每一页,并使用extract text(0方法提取每一页的文本内容,然后将这些文本内容累加到raw text变量中。PDF问答程序的实现方式是利用LangChain已实现的向量存储、嵌入,以及使用查询和检索相关的链来获取外部数据集及处理文档,在进行相关性检索后进行合并处理,将其置入大语言模型的提示模板中,实现与PDF文件交流的目的。例如,你正在为一项重要的报告寻找资料,你必须知道你需要查找的关键词,然后在大量的信息中筛选出你需要的部分。

weixin_43961909的博客 1421

junit测试——java.lang.IllegalStateException: Failed to load ApplicationContext

用Junit测接口的时候报了一个错误 说是加载上下文的问题,这个就懵逼了,但是其他的test测试类是可以正常执行的,那问题就只出在我的这个里面,注解加载路径之类的,那会不会是注解写的有问题 这是我测试类的全部注解,感觉和其他的也没有什么差别啊,在Junit里面找一下有没有和上下文有关的注解加上试一下,不试试怎么知道什么叫绝望呢 @WebAppConfiguration指定加载 A...

明天和意外哪个先到,其实这不重要 1万+

在 ABAP 环境中创建 Job Catalog Entry 和 Job Template 的完整实践指南

摘要:本文介绍了SAP BTP ABAP环境中Application Job的云原生解决方案,对比传统后台作业模式。重点阐述了Job Catalog Entry和Job Template两大核心概念,通过库存重估业务场景演示如何实现可调度类、创建Job Catalog Entry及Job Template。文章详细说明了从ABAP类到Job Catalog Entry再到Job Template的完整链路,并分享实际项目中的设计经验和注意事项,帮助开发者将传统后台作业迁移到Application Job框架

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 232

机器学习实战——疫情数据分析与预测

机器学习如何做到疫情可视化——疫情数据分析与预测实战 本文将带领大家爬取11个国家以及中国31个省(自治区、直辖市)在2022.0101-2022.06.19的新冠疫情数据。并且采用机器学习模型对2022.6.20-2022.6.30每一天的全国确诊人数、死亡人数、治愈人数进行预测,**做出疫情可视化图形并且求出最终的相关系数R2!...

拥有百余位万粉技术博主、200余位可合作代发博主,私域技术社群规模达千人,商务合作私信 10万+

SSH如何使用junit4进行单元测试,java.lang.IllegalStateException: Failed to load ApplicationContext 问题

之前在做单元测试时 一直出现注入问题 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareCont...

Apostle_pilgrimage 1667

手把手教你学Simulink——机器人力控场景实例:基于Simulink的永磁同步电机重力补偿力矩控制仿真

本文介绍了基于Simulink的机器人重力补偿力矩控制仿真方法。针对机器人悬停时电机发热、抖动等问题,提出通过前馈补偿重力转矩的解决方案。文章详细阐述了从机器人动力学建模、重力补偿计算、PMSM转矩控制到系统集成的完整实现流程,并以2-DOF机械臂为例验证了补偿效果。结果表明,重力补偿能显著降低电机电流和拖拽力,提高系统柔顺性。文中还提供了高级功能扩展方向,如参数辨识、摩擦补偿等,为实际工程应用提供了参考框架。

MHD0815的博客 154

spring Junit单元测试事务管理报错:java.lang.IllegalStateException: Failed to load ApplicationContext解决办法

错误信息如下:java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDe

灯初夜未央的博客 9519

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

SSM 之 java.lang.IllegalStateException: Failed to load ApplicationContext 错误解决方案

SSM框架搭建后台项目,为了便于接口开发测试,笔者在项目中使用了Junit测试用例来测试接口,在测试运行后,出现如下错误: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLo...

群鸿 1663

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

java.lang.IllegalStateException: Failed to load ApplicationContext

java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.

qq_40652470的博客 768

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

junit单元测试报错解决之java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframe

**总结;单元测试出错,首先检查Caused by ,然后检查配置文件以及代码是否有问题。 今天在spring项目中进行单元测试,报错,如下图: 错误的信息: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.Default...

天明的博客 3万+

集成JUnit测试错误java.lang.IllegalStateException: Failed to load ApplicationContext

1 详细错误信息 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157) at org.sprin...

641

出现 java.lang.IllegalStateException: Failed to load ApplicationContext或 java.lang.NullPointerExcept错误

中并没有进行别名配置,导致出现如下错误,找了好久才发现忘记进行别名配置了。并不会自动进行别名配置,也需要在配置文件中进行别名配置。请参考这位博主的博客,希望对大家有帮助。3.由于这里我直接使用的是。实现分页查询,自定义。类的全限定名,而我在。

星球奋斗者 709

springjunit测试报 java.lang.IllegalStateException: Failed to load ApplicationContext

java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’ defined in class path resource [applicationContext.xml]: Initialization of bea

weixin_49723367的博客 702

JUnit测试类报错:java.lang.IllegalStateException: Failed to load ApplicationContext

问题描述 运行以下JUnit测试类时,报以下错误信息: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132) at org.sprin

大强博客 2862

java.lang.IllegalStateException: Failed to load ApplicationContext报错

java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) at org.springframework.test.context.support.D

yunnuo的博客 1045

SSH基于注解的junit测试:java.lang.IllegalStateException: Failed to load ApplicationContext问题

最近在做项目的时候遇到如下的问题,虽然这个问题网上一查一大堆,但是没有解决我的问题。java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157

oymaidi的专栏 2982

Caused by: java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found

使用Junit进行测试时遇到报错信息如下(一定需要注意看上下文,根据上下文进行问题的处理): 2020-11-03 14:08:17,113 ERROR [org.springframework.test.context.TestContextManager] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@

Simon111Qiu的博客 2497

解决Spring框架使用Junit4测试出现的问题:java.lang.IllegalStateException: Failed to load ApplicationContext

java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelega...

jinchunzhao的博客 1万+
上一篇: 关于default-action-ref的思考
下一篇: SQL Error: 1064, SQLState: 42000错误原因
backzero
博客等级 码龄15年 3粉丝 36原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值