failed to load applicationContext
来源:互联网 发布:阿里云备案照片 编辑:程序博客网 时间:2024/05/29 03:20
用spring4做个单元测试,报failed to load applicationContext
代码如下:
1.接口
package com.springinaction.test;public interface CompactDisc {public void play();}2.实现类
package com.springinaction.test;import org.springframework.stereotype.Component;@Componentpublic class SgtPeppers implements CompactDisc{private String title = "Sgt. Pepper's Linel Hearts Cloub Band";private String artist = "The Beatles";@Overridepublic void play() {System.out.println("Playing " + title + " by " + artist);}}
3.配置类(注解组件扫描):@ComponentScan注解,这个注解能够在Spring中启动组件扫描,默认会扫描与配置类相同的包
package com.springinaction.test;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;@Configuration@ComponentScanpublic class CDPlayerConfig {}4.测试类
package com.springinaction.test;import static org.junit.Assert.*;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes=CDPlayerConfig.class)//@ContextConfiguration(locations={"classpath:NewFile.xml"})这里是xml启动组件扫描,因为我们用的是注解扫描,所以注释public class CDPlayerTest {@Autowiredprivate CompactDisc cd;@Testpublic void cdShouldNotbeNull(){assertNotNull(cd);}}原因是缺少Spring的jar包,在http://repo.spring.io/release/org/springframework/spring
中下载了spring-framework-4.2.0.RELEASE-dist.zip,解压完后把包都导了进入,就ok了
1 0
- failed to load applicationContext
- Failed to load ApplicationContext
- Failed to load ApplicationContext
- IllegalStateException: Failed to load ApplicationContext
- java.lang.IllegalStateException: Failed to load ApplicationContext
- java.lang.IllegalStateException: Failed to load ApplicationContext
- java.lang.IllegalStateException: Failed to load ApplicationContext
- Failed to load ApplicationContext java.lang.IllegalStateException:
- Spring错误笔记--Failed to load ApplicationContext
- java.lang.IllegalStateException: Failed to load ApplicationContext
- 解决IllegalStateException: Failed to load ApplicationContext 方法
- java.lang.IllegalStateException: Failed to load ApplicationContext
- java.lang.IllegalStateException: Failed to load ApplicationContext
- java.lang.IllegalStateException: Failed to load ApplicationContext
- 求助!!!!Failed to load ApplicationContext错误
- java.lang.IllegalStateException: Failed to load ApplicationContext
- java.lang.IllegalStateException: Failed to load ApplicationContext
- java.lang.IllegalStateException: Failed to load ApplicationContext
- Linux原始套接字学习总结
- 无法解析的外部符号(或者未将对象引用设置到对象实例)
- Android Studio教程从入门到精通
- 第十、十一周项目一-点-圆-圆柱类族的设计(3)
- 优先级队列 C++ 模板实现
- failed to load applicationContext
- iOS开发系列--视图切换
- linux命令--ldconfig和ldd用法
- 知识点杂记
- scala中的下划线含义
- 设计模式之单例模式(Singleton)
- [閒聊]一個省電功能的反向思考
- 跨域名相关知识
- ADT下载地址(含各版本),最新ADT-23.0.6