spring junit 做单元测试,报 Failed to load ApplicationContext 错误

spring junit 做单元测试,报 Failed to load ApplicationContext 错误。

查找了好一会,最后发现。@ContextConfiguration(locations = { "classpath:/spring/applicationContext.xml",
"classpath:/spring/app-config.xml", ……

改成

@ContextConfiguration(locations = { "classpath*:/spring/applicationContext.xml",
"classpath*:/spring/app-config.xml",

就好了。

可能是因为项目里引用了其他项目,有相同名称的spring配置文件导致的。在classpath后加上*就可以了。

如果以上未解决

可以尝试:Clean Project -> mvn install

时间: 2024-10-10 07:53:55

spring junit 做单元测试,报 Failed to load ApplicationContext 错误的相关文章

小型SSM项目出现Failed to load ApplicationContext错误的解决方法(个人向)

使用单元测试的时候,出现了Failed to load ApplicationContext错误,在添加了一个新的Mapper.xml文件才出现的,在保证其他配置文件没有出错的情况下,检查mapper的id,是否重名,以及mapper文件报错,检查是否在SQL语句中出现<,>号,都要用 >  >  大于号 <  <  小于号 来替换 原文地址:https://www.cnblogs.com/Xjx-zhenCai/p/11398409.html

spring实战4 Failed to load ApplicationContext

今天看到spring的自动装配组件,照着书上的敲了下来报错了 代码: 接口 public interface CompactDisc { void play();} 实现类 import org.springframework.stereotype.Component; @Componentpublic class SgtPeppers implements CompactDisc { private String title = "命运交响曲"; private String art

spring集成Junit做单元测试及常见异常解决办法

spring-test依赖包 <!--Spring-test --> <!-- https://mvnrepository.com/artifact/org.springframework/spring-test --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version&g

spring中junit 提示Failed to load ApplicationContext

错误提示: 1:java.lang.IllegalStateException: Failed to load ApplicationContext 2:Error creating bean with name 'userService' defined in class path resource [UserService.xml]: Initialization of bean failed; nested exception is org.springframework.aop.fram

SpringBoot报错:Failed to load ApplicationContext(javax.websocket.server.ServerContainer not available)

引起条件: WebSocket+单元测试,单元测试报错! 解决方法: SpringBootTest增加webEnvironment参数. https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html#boot-features-testing-spring-boot-applications @SpringBootTest(webEnvironment = SpringBootT

junit测试时,出现java.lang.IllegalStateException: Failed to load ApplicationContext

课程设计要求进行junit测试,我是在已经做好的ssh项目上做的测试,测试类代码如下 package com.zhang.web.services; import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import javax.annotation.Resource; import org.junit.runner.RunWith; im

java.lang.IllegalStateException: Failed to load ApplicationContext

1.错误描述 INFO:2015-02-05 22:14:21[main] - Loading XML bean definitions from class path resource [applicationContext.xml] INFO:2015-02-05 22:14:22[main] - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning INFO:2015-02-05

java.lang.IllegalStateException: Failed to load ApplicationContext(2)

错误提示: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]: Error sett

常见Failed to load ApplicationContext异常解决方案!!

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